grade and age

can yall help me write a C++ Program where a user enters an age from 5 to 18 and print what grade that person should be in?
Sure.

But first, let's see what you've managed to come up with on your own.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>

using namespace std;

void whichGrade(int &age){
	cout << "Enter age: ";
	cin >> age;

	if (0 == age){}
	else if (age < 5 || age > 18){
		cout << "Invalid age." << endl;
	}
	else if (5 == age){
		cout << "Kindergarten." << endl;
	}
	else if (6 == age){
		cout << "Kindergarten / 1st grade." << endl;
	}
	else if (7 == age){
		cout << "1st / 2nd grade." << endl;
	}
	else if (8 == age){
		cout << "2nd / 3rd grade." << endl;
	}
	else if (9 == age){
		cout << "3rd / 4th grade." << endl;
	}
	else if (18 == age){
		cout << "12th grade" << endl;
	}
	else {
		cout << age - 6 << "th / " << age - 5 << "th grade." << endl;
	}
}

int main() {
	int age;
	
	cout << "Enter your age to see what grade you should be in." << endl;
	cout << "Enter 5 - 18 for age, or 0 to exit." << endl;
	
	do {
		whichGrade(age);
	} while (age);
	
	return 0;
}
Topic archived. No new replies allowed.