Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am a beginner in C++ and I was trying to write a program that finds the average of two numbers, but when I run the program, the window disappears without allowing me to see the result. Can someone please help me? Thanks

 #include <iostream>
 using  namespace std;
 int main()
 {
 int number1,number2,answer;
 cout << "number1? ";
 cin >> number1;
 cout << "number2? ";
 cin >> number2;

 answer = (number1 + number2)/2;

 cout << answer<<endl;
 return 0;
 }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
727 views
Welcome To Ask or Share your Answers For Others

1 Answer

Solution #0 (proper):
Run program from shell (cmd.exe, bash)

Solution #1 (proper):
Run program from orthodox file manager. Far Manager or midnight commander.

Solution #2 (alternative);
Redirect output to file. program.exe >file.txt from command line.

Solution #3 (improper):
Launch message box, use "sleep"/"Sleep" to delay program termination.

Solution #4 (improper):
Request user input at the end of program.

Solution #5 (improper):
Set breakpoint on "return 0", debug the program.

Solution #6 (windows+msvc):
Launch program from msvc by Ctrl+F5 using debug build. You'll get "press key to continue" prompt.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...