Develop a C++ program to determine a student’s letter grade based on a given integer test score. If the test score is 90 or more, the grade is ‘A’. If the score is between 80 and 89, the grade is ‘B’. If the score is between 70 and 79 the grade is ‘C’. If the score is between 60 and 69 the grade is ‘D’. If the score is less than 60 the grade is ‘F’.

I have this part, but when it comes to printing the name I can't seem to get it. Heres what I have so far. I would like it to print something like: the persons name then the letter grade

#include <iostream>
#include <string>
using namespace std; 

int main()
{
//input data
	int grade=0;
	string name ="";
	
	cout << "Please enter your name: ";
	cin >> name;
	
	cout << "Please enter your grade: ";
	cin >> grade;
	
	if (grade >= 90) 
		cout << "Your letter grade is A";
	else if (grade >=80)
		cout << "Your letter grade is B";
	else if (grade >=70)
		cout << "Your letter grade is C";
	else if (grade >=60)
		cout << "Your letter grade is D";
	else 
		cout << "Your letter grade is F" << endl;
	
return 0;
}

You don't see the name because the code does not output it anywhere, you must add

cout <<  name;

at a proper location.

I tried that but then it displayed the name right on top of the text something like:
cout << name;
cout << "Your grade is A"

that would print MikeYourgrade is A. How do I get a space in between?

Yupp, you need to include a cout << name;

For the name to show up.

It's always the little things that we forget!


edit


cout << name << " " << grade<< endl;

Thanks for the help, I figured it out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.