0

Why isn't my code Working?

Im new to c++ #include <iostream> using namespace std; int main() { int x = 30; int y; while(x > y) { int a, b; cout << "Write A Number \n"; cin >> a; cout << "Write Another Number \n"; cin >> b; int answer; cout <<"The Result Is :" << a + b << endl; //this part doesn't work , why? cout <<"Redo?"<<endl; cin >> answer; if(int answer = 0){ break;}} return 0; }

3rd Jul 2020, 11:28 AM
Gianluca
Gianluca - avatar
4 ответов
+ 2
First of all, integer x and y are useless, you just want to create an infinite loop which can be done using while(1) // this will cause infinite loop Second, in the last if statement there is no need of int, it should be like If(answer==0) //Code Change these things, and your code should work. And a suggestion tell user that enter 1 to redo and 0 to exit. Otherwise how would a user know that 0 is for exiting program. Happy coding😊
3rd Jul 2020, 12:46 PM
Alaska
Alaska - avatar
+ 1
I was going to write the instructions , btw thanks!!!!
3rd Jul 2020, 12:47 PM
Gianluca
Gianluca - avatar
0
It's better u use do while loop here.
3rd Jul 2020, 11:42 AM
123
0
Thanks!
3rd Jul 2020, 11:56 AM
Gianluca
Gianluca - avatar