What's wrong with my Countdown Code in C++? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

What's wrong with my Countdown Code in C++?

#include <iostream> using namespace std; int main() { int n; cin >> n; { while (n >= 1) { cout << n << endl; n = n-1; if (n % 5 == 0) { cout << "Beep" << endl; }}} return 0; } it's currently 1 second off the requirement, for example it says "Beep" after 11 instead of 10

26th Mar 2021, 4:56 PM
Foxel
Foxel - avatar
1 Réponse
+ 4
You can use n = n -1 or decrement(n--) outside if statement. Also there is an extra "{}" before while loop while (condition){ if (condition){ } n = n-1; }
26th Mar 2021, 5:10 PM
Simba
Simba - avatar