Cannot type in CMD

Mar 7, 2013 at 2:53am
I recently came across the issue of not being able to type in my cmd console. I was working on a project in MSV; while starting a new one I was unable to type in the console. *After compiling with no errors.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

//@author Will A. Training Exercise Grade Programming

int main()
{
	int grade = NULL;
	bool repeat = true;

	std::cout<<"Grade Programming Created By Will A.\n";

	while(repeat)
	{
		if((grade <=100)&&(grade >=90))
		{
			std::cout<<"Your grade is an A\n";
		}
	}
}



Although in another project I worked on previously I still may type in the console.


Mar 7, 2013 at 2:55am
You aren't asking for any input?
Mar 7, 2013 at 3:18am
Well, I added

1
2
std::cout<<"Your grade is an A\n";
			std::cin>>grade;


I'm most likely completely wrong, sorry for my ignorance.

If you don't mind assisting me a tad more.
Mar 7, 2013 at 3:22am
So it still doesn't let you type with that there?

That's rather odd, are you sure the window is in focus?
Mar 7, 2013 at 3:27am
How do you mean? ...in focus?
Mar 7, 2013 at 3:30am
Can you please post your code WITH WillDesigned's code inserted.
Mar 7, 2013 at 3:32am
start with something like this,,,,

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
#include <iostream>

using namespace std;

//@author Will A. Training Exercise Grade Programming

int main()
{
	int grade = NULL;
	char repeat = 'y';

	cout<<"Grade Programming Created By Will A" << endl;

	while(repeat == 'y')
	{
		cout<<"Enter your grade:" << endl;
		cin >> grade;

		if((grade <=100)&&(grade >=90))
		{
			cout<<"Your grade is an A"<< endl;
		}

		cout<<"Enter a new grade? Y OR N:" << endl;
		cin >> repeat;
		system("cls");
	}
	return 0;
}
Mar 7, 2013 at 3:36am
Here is what I came up with very quickly. The while loop is currently unnecessary but I left it in for your sake.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

//@author Will A. Training Exercise Grade Programming

int main()
{
	int grade = NULL;
	bool repeat = true;

	std::cout<<"Grade Programming Created By Will A.\n";
	std::cout << "Enter your grade: ";
	std::cin >> grade;
	while(repeat){
		if((grade <=100)&&(grade >=90))
		{
			std::cout<<"Your grade is an A\n";
		}
	}
} 
Mar 7, 2013 at 3:42am
@CodeWeaver @joneele @firedraco

Thank you for the help! Glad to know people are considerate unlike other forums I've previously was part of.
Mar 7, 2013 at 4:11am
Ah, I see. std::cin was inside your if check, which is never true because grade is 0 and is never changed.

Btw:

int grade = NULL;

This sets grade to 0, *not* something like NULL or NaN. You should only use NULL with pointers.
Mar 8, 2013 at 1:10am
Yeah. Sorry about not presenting the full code.


I asked my friend whom has experience in c++. (Early till this moment)
He said it doesn't make much a difference in this case. Thanks for telling me that, I'll make sure to use that to the best of my knowledge.
Topic archived. No new replies allowed.