How could I print the input in the same line?

I'm trying to input the grade score next to the question but in the console, the input goes to the next line.

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
#include "stdafx.h"
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	
	// Constants for grade thresholds
	int A_SCORE = 92,
	    B_SCORE = 83,
	    C_SCORE = 75,	
	    F_SCORE = 75;
	
	int testScore;
	
	// Get numeric test score
	cout << "Enter your test score to know your letter grade. \n"; 
	cin >> testScore;
	
	while (testScore > 0)
	
	{
		// Determine the letter grade.
		if (testScore >= A_SCORE)
			cout << "Your grade is an A.\n";
		else if (testScore >= B_SCORE)
			cout << "Your grade is a B. \n";
		else if (testScore >= C_SCORE)
			cout << "Your grade is a C. \n";
		else if (testScore < F_SCORE)
			cout << "Your grade is F. \n";
		cout << "Enter your test score to know your letter grade. \n"; 
		cin >> testScore;
	}
	
	cout << "Invalid test score. \n";
	cout << "Please enter a valid test score to know your letter grade. \n"; 
	cin >> testScore;
	
	return 0;	
		
}
@kdjm77

If you're wanting the input to be on the same line, remove the '\n' the cout lines. Those mean 'NewLine'
Then don't print a newline (\n) before they've entered their score.

1
2
3
4
	// Get numeric test score
	cout << "Enter your test score to know your letter grade. ";  // no \n;
	cin >> testScore;
	cout << "\n"; // might want one here instead? 
Last edited on
None of these solutions did it for me. The output needs to look like this example:

Please enter your score (negative value to quit) --> 78
The grade is C
Please enter the score --> 50
The grade is F
@ldjm77

Show us what the program looks like now, and we can then give more help.
Topic archived. No new replies allowed.