Countdown project help no getting an output

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".

Sample Input:
12

Sample Output:
12
11
10
Beep
9
8
7
6
5
Beep
4
3
2
1

What I have tried to answer this I keep getting no output for some reason. Please see below for my attempt.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  #include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    
    //your code goes here
    while (n >= 1) 
    {
    	cout << n << endl;
    	
    	if (n % 5 == 0)
    	{
    		cout << "Beep" << endl;
    	}
    	
    	n--;
    }
    
    return 0;
}
¿did you input the start number?
¿or is the problem that the console closes down and you don't see the output of your program?
The problem is that after I input a number I am not getting any output. What I am using just says no output.
Hello Profio,

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.

Have a look at this and give it a try.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <limits>

using namespace 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.
}


Prefer to use the new line (\n) over the "endl".

Andy
Topic archived. No new replies allowed.