- 3

22 End of module project

How can i make the ‘beep’ below the 5 and the 10 rather than above them and remove the ‘beep’ below 1?? Thats my code: #include <iostream> using namespace std; int main() { int n; cin>>n; //your code goes here n=12; while(n>=1){ cout<<n<<endl; n=n-1; if(n%5==0){ cout<<"Beep"<<endl; } } }

18th Mar 2021, 11:35 AM
Mustafa Mansuor
Mustafa Mansuor - avatar
23 Respuestas
+ 2
I already explained, but I will try to do it again with other words... n store the user input by using 'cin' the 'for' loop takes 3 parts inside parenthesis after the 'for' keyword: 1) initialization (executed once at loop start), usually initialization of counter variable 2) condition (checked at start of each loop iteration) 3) part executed at end of each iteration (usually in/decrementation of variable counter) you 'for' loop first part set n to 12, wich is the example case provided, but you need to use the value assigned to n by 'cin'... so you just need to leave empty the initialization part ;)
18th Mar 2021, 1:12 PM
visph
visph - avatar
18th Mar 2021, 11:41 AM
JaScript
JaScript - avatar
+ 1
your code only handle the example test case... you must use n given by input: for (; n>=1;n--){ ... don't forget the first semi colon ;)
18th Mar 2021, 12:07 PM
visph
visph - avatar
+ 1
your code get n from user input, but redefine n to 12 (the example test case) in the first part of the for loop parenthesis... you must leave this part empty, as n is still initialized with the right value ^^
18th Mar 2021, 12:18 PM
visph
visph - avatar
+ 1
Matt Burtz that's not your thread: open your own question thread, and request for help in it, by providing your code attempt (better to share the link to a code playground)
29th Jun 2021, 12:12 PM
visph
visph - avatar
0
you should iterate in right order: from 1 to n, not from n to 1 ;)
18th Mar 2021, 11:40 AM
visph
visph - avatar
0
made some changes and it gives the right order and the beep where they should be, but still it doesnt indicate that my answer is right. #include <iostream> using namespace std; int main() { int n; cin>>n; for(int n=12;n>=1;n--){ if(n% 5 == 0) { cout << n<< endl; cout << "Beep" << endl; } else cout << n<< endl; } return 0; }
18th Mar 2021, 11:52 AM
Mustafa Mansuor
Mustafa Mansuor - avatar
0
copy the task description/requirement here to refresh our memory ;)
18th Mar 2021, 11:55 AM
visph
visph - avatar
0
still wouldnt work
18th Mar 2021, 12:03 PM
Mustafa Mansuor
Mustafa Mansuor - avatar
0
copy the task description/requirement here to refresh our memory ;)
18th Mar 2021, 12:04 PM
visph
visph - avatar
0
visph 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
18th Mar 2021, 12:04 PM
Mustafa Mansuor
Mustafa Mansuor - avatar
0
visph (sorry)huh..?
18th Mar 2021, 12:16 PM
Mustafa Mansuor
Mustafa Mansuor - avatar
0
still bro..
18th Mar 2021, 12:40 PM
Mustafa Mansuor
Mustafa Mansuor - avatar
0
???
18th Mar 2021, 12:41 PM
visph
visph - avatar
0
still wouldnt work although i think i dont think i fully understood the last thing u said
18th Mar 2021, 12:43 PM
Mustafa Mansuor
Mustafa Mansuor - avatar
0
just replace your 'for' line with the one I given previously, without missing the first semi colon (;)
18th Mar 2021, 12:51 PM
visph
visph - avatar
0
visph it worked thank you, i just need explaination to what was wrong and what changed
18th Mar 2021, 1:03 PM
Mustafa Mansuor
Mustafa Mansuor - avatar
0
ooooohh,thanks budd!! much appreciation!!
18th Mar 2021, 1:16 PM
Mustafa Mansuor
Mustafa Mansuor - avatar
0
What does that first semi colon do?
29th Jun 2021, 10:24 AM
Matt Burtz
0
Matt Burtz for loop parenthesis must provide 3 parts, semi colon separated, even if you don't need to do something inside... first part is initialization (done only once at start of loop), so if the variable is already initialized before, you have no need of content in it, but you must mark the end of this empty part with a semi colon ;)
29th Jun 2021, 10:30 AM
visph
visph - avatar