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; }
4 Respuestas
+ 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😊
+ 1
I was going to write the instructions , btw thanks!!!!
0
It's better u use do while loop here.
0
Thanks!