0
Where I'm making mistake ?? Can someone help please 🥺🥺
4 Antworten
+ 1
// Jungle camping c++
#include <iostream>
#include <string>
using namespace std;
int main(){
string noise ;
string Rawr = "Rawr", Chirp = "Chirp", Ssss = "Ssss";
for(int i = 0; i<4; i++) {
cin >> noise ;
if (noise == Rawr){
cout << "Tiger ";
}
else if (noise == Chirp){
cout << "Bird " ;
}
else if (noise == Ssss) {
cout << "Snake " ;
}
else
{
cout << " " ;
}
}
return 0;
}
I removed the syntax errors :
1_missed opening brace for the else statement
2_Invalid declaration of the variables Rawr, Chirp and Ssss
3_Invalid use of while loop, so I replaced it by a for loop
Input : Ssss
Output : Snake Snake Snake Snake
0
you were trying to use a while as if it were a for, and it was wrong too, anyway ... very good! Keep practicing! keep learning!
Is this what you expected?
https://code.sololearn.com/clJ2LrLVm9f1/?ref=app
0
VCoder when ı look into other examples some use brace and some not in else. How can I know where to use or not
0
Lalala , It can be omitted if you only have one line within the code block.
Anyway, if you are a beginner, maybe you should always use them
Ex .: else return 1;
Another example, look at my code again, now it has no braces:
https://code.sololearn.com/clJ2LrLVm9f1/?ref=app