#include <iostream>
usingnamespace std;
struct Date{
int day,month,year;
};
struct Time{
int hours,minutes;
};
struct Exam{
Date d;
Time t;
string course_name;
int RoomNum;
};
void getData(Exam&);
int main() {
cout << "Enter your exam Information" << endl;
Exam e[3];
for (int i = 0; i < 1; i++) {
getData(e[i]);
}
for (int j = 0; j < 1; j++) {
cout<<e[j].course_name<<" : "<<e[j].d.month<<"-"<<e[j].d.day<<"-"<<e[j].d.year<<" "<<"at "<<e[j].t.hours<<":"<<e[j].t.minutes<<" "
<<" in Room "<<e[j].RoomNum;
}
}
void getData(Exam&) {
Exam e;
cout << "Enter the month of your exam" << endl;
cin >> e.d.month;
cout << "Enter the day of your exam" << endl;
cin >> e.d.day;
cout << "Enter the year of your exam" << endl;
cin >> e.d.year;
cout << "Enter the hours of your exam" << endl;
cin >> e.t.hours;
cout << "Enter the min of your exam" << endl;
cin >> e.t.minutes;
cin.ignore();
cout << "Enter the course name of your exam" << endl;
getline(cin,e.course_name);
cout << "Enter the Room number of your exam" << endl;
cin >> e.RoomNum;
}
0. You have dynamic user input without any examples... what is example of problematic input?
1. What's the Expected output?
2. What's the Actual output?
Other useful info -- only certain inputs fail, or does every input fail?
The first thing I found is getting the user input.
The "getData" function definition looks good for a prototype, but will not work as a function definition. You forgot the variable name. The "Exam e;" you defined inside the function is lost when the function ends. It may be a personal thing with me, but I like the prototype to match the function definition. This way there is less chance of missing something like the variable name in the function definition.
So void getData(Exam&) should look like void getData(Exam& e).