Ask coding questions

← Back to all posts
Need Help with break
KASON123 (6)

So im trying to break a no Question and i dont know how to create a loop for this iv done research and everything i cant find a good one

#include <iostream>
using namespace std;

int main() {

int dogs = 3;
int cats = 4;
int yes;
int no;

cout << "There are 3 dogs" << endl;
cout << "There is also 4 cats" << endl;
cout << "Do u want to play a game?" << endl;
cin >> no;

if (no)
I want my break to be right here or somewhere here but dont know how to
cout << "Bye Bye" << endl;
else
cin >> yes;

cout << "If you add dogs + cats what would you get" << endl;

}

Comments
hotnewtop
Coder100 (17034)

that is some invalid code. You need to use curly braces, like this:

int dogs = 3;
int cats = 4;
int yes;
std::string no;
int answer = 7;


cout << "There are 3 dogs" << endl;
cout << "There is also 4 cats" << endl;
cout << "Do u want to play a game?" << endl;
cin >> no;

if (no) {
  cout << "Bye Bye" << endl;
}
else {
cin >> yes;


cout << "If you add dogs + cats what would you get" << endl;

cout << dogs + cats;
cin >> answer;

if (7)
cout << "good job you got it " << endl;
}

so you and C++ are more clear about what goes where.

DavidShen2 (60)

I'm not completely sure what you are asking. If you want to end the program, use

return 0;

This exits the main function.