0

Im having a technical issue while trying to code C++ in visual Studio. My code was working fine until it required me to use input from the user, so i coded a simple program like the one below

int chairs(void) {

 int count;

 cout << “Enter the number of chairs: “;

 cin >> count;

 return count;

}

When i run the code the console window opens and allows the user to enter the number of chairs, however, once the value has been entered the window immediatly closes and theres no output in visual studios own console window. How can i fix this issue? is there a certain plug-in or settings i need to change? I knoww you can code your own settings in user settings. Thankyou

selbie
  • 100,020
  • 15
  • 103
  • 173
David Ling
  • 145
  • 1
  • 12

2 Answers2

1

Simply add getch(); before the return statement. It will then wait for you to press any button to close.

Md Golam Rahman Tushar
  • 2,175
  • 1
  • 14
  • 29
1

From the main menu, select Tools,then Options.

Make sure this setting is not enabled under Debugging: "Automatically close console window when debugging stops".

enter image description here

selbie
  • 100,020
  • 15
  • 103
  • 173