Visual studio and c++

closed account (ENh0ko23)
When i try to enter in a number to the compiled code on the black screen, the black screen shuts off once i enter a number and press enter. It compiles so the code cant be wrong.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;
int main()

{
	int number;
	cout << "Enter an integer and I will tell you if it" << endl;
	cout << "is odd or even." << endl;
	
	cin >> number;

	if (number % 2 == 0)
		cout << number << " is even.\n";
	else
		cout << number << " is odd.\n";



	
	return 0;
}
lol it compiles so it can't be wrong? I wouldn't bet on this going forward :)

That aside,
you have 4 main choices.
1) you can open a console, navigate to the program, and run it via "dos" commands.
2) you can add the command "system("pause"); before "return 0;"
3) you can write a batch file to call the program and append the system pause to it outside the code.
4) you can read in a bogus value at the end of the program (cin >> bogus or something)
Last edited on
closed account (ENh0ko23)
the system pause helped! thanks
You can avoid the use of "system" by hitting "Start Without Debugging" (Ctrl + F5) from the "Debug" tab in the menu bar.
Topic archived. No new replies allowed.