+ 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++)?
12 ответов
+ 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++;
)