Just started learning C++ today. I'm writing a program to keep up with school assignments.
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <string>
struct Assignment
{
string Period;
string Title;
string Page;
string Date;
string Instruct;
};
void NewAssignment()
{
system("CLS");
Assignment Work;
cout << "New Assignment Entry" << endl;
cout << "--------------------------" << endl << endl;
cout << "Period: ";
getline(cin, Work.Period);
cout << "Title: ";
getline(cin, Work.Title);
cout << "Page Number: ";
getline(cin, Work.Page);
cout << "Date: ";
getline(cin, Work.Date);
cout << "Instructions: ";
getline(cin, Work.Instruct);
WriteInfo(Work); //Writes to a file
}
int main()
{
system("CLS");
int choice;
cout << "Assignment Manager" << endl << endl;
cout << "1: Add an assignment" << endl;
cout << "2: Browse saved assignments" << endl;
cout << "3: Delete an assignment" << endl;
cout << "4: Exit" << endl << endl;
cin >> choice;
if(choice == 1)
{NewAssignment();}
else if (choice == 2)
{main();}
else if (choice == 3)
{main();}
else if (choice == 4)
{exit(0);}
else{main();}
return 0;
}
It screws up somewhere in the NewAssignment function. When it is called it gives me
New Assignment Entry
------------------------
Period: Title:
It completely skips over getting input for Work.Period. It works right when I use cin but then all of the others do the same, and I must use getline() so spaces will be recognized.