So I am completely brand new to C++ and learning the basics I watched a YouTube video to help me set up VSC and C++ correctly and initially it was working, I was running programs and the output was showing in the terminal.
However, on this specific program whilst I am trying to implement a while loop, the code simply wont run.
#include
int main()
{
int x = 1;
int number;
while(x <= 5){
std::cin >> number;
x ++;
}
return 0;
PS C:UsersRolla> cd "c:UsersRolla" ; if ($?) { g++
ProgramLoop.cpp -o ProgramLoop } ; if ($?) { .ProgramLoop }.
I repeatedly get this error every time I press the run code button.
I have tried to reboot my PC, close VSCode and restart it on task manager and honestly I am such a beginner to C++ and programming as a whole but I can’t see any syntax errors that I done in terms of semi colons or parenthesis etc.
2
Answers
The part that I was forgetting was the enter a number please.
The code you have written is working perfectly without any issues. The main issue with this code is that it is not structured to achieve any specific output or functionality beyond accepting five integer inputs from the user. In order to see the results in the output/terminal section, you must have to update the code accordingly,
You can achieve that by adding a small output function into the code, as given in the below example,
std::cout
is being used for displaying the value of the variable.std::endl
is being used to change the line.Output of the code can be,
For more help, you can refer to the following websites (personal preference)
C++ reference
Geeks for Geeks
I hope it helped you :>