Explain this to me as I were a four years old kid | Sololearn: Learn to code for FREE!

+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++)?

c++

12 Answers

New Answer

+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

+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

+2

Diamond Garcia Copying without understanding maybe harmful.

+1

Hey Diamond Garcia ,follow C++ course https://www.sololearn.com/learning/1616/

+1

MichaΕ‚ Doruch, i copied it from someone else's code bit which was mistake; just for my question

+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

+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; }

0

πŸ…°πŸ…Ή πŸ…πŸ…πŸ…πŸ…πŸ…£ , that's why i created this questionπŸ˜‚

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++; )