Hello everyone,
Sorry if this is a really beginner question but I am struggling to figure out where I am going wrong. The question is to:
- You need to make a countdown app.
Given a number N as input, output numbers from N to 1 on separate lines.
Also, when the current countdown number is a multiple of 5, the app should output "Beep".
To the right of your code box is a gear icon with Edit & Run. Pressing that and running your program work as expected. Also I put your program in MSVS 2017 and it ran as expected.
You need to mention what IDE/compiler you are using to better where any difference may be.
#include <iostream>
#include <limits>
usingnamespace std; // <--- Best not to use.
int main()
{
int startNum{}; // <--- ALWAYS initialize your variables.
// <--- Needs a prompt.
cin >> startNum;
//your code goes here
//while (startNum >= 1)
while (startNum) //<--- When this reaches (0)zero the loop ends.
{
cout << startNum << '\n';
if (startNum % 5 == 0)
{
cout << "Beep\n";
}
startNum--;
}
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // <--- Requires header file <limits>.
std::cout << "\n\n Press Enter to continue: ";
std::cin.get();
return 0; // <--- Not required, but makes a good break point.
}