Explain this to me as I were a four years old kid | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Explain this to me as I were a four years old kid

using namespace std; int main() { int foul; cin >> foul; if(foul>10){ cout << "High Five"; } else if{ if(x<1) cout << "shh"; } else{ for(int i=0; i<foul; i++) cout<< "Ra!"; } Why do we use: for(int i=0; i<foul; i++)?

26th Apr 2021, 3:54 PM
Shikaki Van D Wolfgang Sebastian
Shikaki Van D Wolfgang Sebastian - avatar
9 Answers
+ 2
For loop is for repetition suppose u entered a number foul= 4 Then your loop will run upto 4 times For(int i=0;i<4;i++) Here your cout statement will execute 4 times
26th Apr 2021, 3:59 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
Btw this else if statement is invalid. You have to make it "else if(...){}" Secondly, you tried to compare x with 1, but you never declared such variable
26th Apr 2021, 4:08 PM
Michal Doruch
+ 2
Diamond Garcia Copying without understanding maybe harmful.
26th Apr 2021, 4:31 PM
A͢J
A͢J - avatar
26th Apr 2021, 4:15 PM
Giriraj Yalpalwar
Giriraj Yalpalwar - avatar
+ 1
Michał Doruch, i copied it from someone else's code bit which was mistake; just for my question
26th Apr 2021, 4:23 PM
Shikaki Van D Wolfgang Sebastian
Shikaki Van D Wolfgang Sebastian - avatar
+ 1
You have written the code and you only don't know it's usage. Please refresh your basics ,if you have forgotten about it
26th Apr 2021, 4:45 PM
Atul [Inactive]
+ 1
Atul , Just got bit confused and copied someone else’s code which was 60-70% accurate 😅😆 So, I wrote this code after i understood what i had to. #include <iostream> using namespace std; int main() { int x; cin>>x; if (x>10){ cout<<"High Five"; } else if(x<1){ cout<<"shh"; } else{ for (int i=0;i<x;i++) cout<<"Ra!"; } return 0; }
26th Apr 2021, 4:51 PM
Shikaki Van D Wolfgang Sebastian
Shikaki Van D Wolfgang Sebastian - avatar
0
🅰🅹 🅐🅝🅐🅝🅣 , that's why i created this question😂
26th Apr 2021, 4:35 PM
Shikaki Van D Wolfgang Sebastian
Shikaki Van D Wolfgang Sebastian - avatar
0
Bhupesh 💔💔 , It takes an input and shows one among three outputs. I was wondering why the line for(int i=0;i<x;i++) was written, So, when i got some answers, i realized that i just got confused somehow and had to understand that code as: for( int x; i=0; i++; )
27th Apr 2021, 3:36 PM
Shikaki Van D Wolfgang Sebastian
Shikaki Van D Wolfgang Sebastian - avatar