I'm currently reading SAMS' C++ Primer Plus, and am attempting to do one of the programming exercises. The goal of the program is to ask for the person's first and last names, the grade that they want, and their age. I can do everything easily except for the grade part. The grade is supposed to end up being one letter grade worse than the grade the user inputs. I get a nasty error when I try to use cin to get the value of the person's grade. I'm not allowed to use if statements, switch statements, etc. because I haven't gotten that far in the book and I need to go only on information the book has given me thus far. Without further ado, here's the code:
Thanks to anyone who can figure out what I'm doing wrong. I'm sure it's very easy.
PHP:
#include <iostream>
int main()
{
using namespace std;
char firstname[25];
char lastname[25];
enum grades {A = 4, B = 3, C = 2, D = 1};
grades yourgrade;
int age;
cout << "What is your first name? ";
cin.getline(firstname, 26);
cout << "What is your last name? ";
cin.getline(lastname, 26);
cout << "What letter grade do you deserve? ";
cin >> yourgrade;
cout << "What is your age? ";
cin >> age;
yourgrade = grades(yourgrade - 1);
cout << "Name: " << lastname << ", " << firstname << endl;
cout << "Grade: " << yourgrade << endl;
cout<< "Age: " << age << endl;
return 0;
}
Thanks to anyone who can figure out what I'm doing wrong. I'm sure it's very easy.