I need help with my code just give me the hint pls | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

I need help with my code just give me the hint pls

im recently learning c++ #include <iostream> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <conio.h> #include <windows.h> using namespace std; int main() { int answer; while(true) { system("color F0") ; int life=3,point=0; while(life!=0) { int number,random; srand ( time(NULL) ); random= rand()%5 + 1; cout << "Choose a number between 1 and 5: "; cin >> number; if (number>5 || number<1) { cout << "Error.The number is not correct."; Sleep(1000); cout << "\tYou lost 2 life\n"; life-=2; Sleep(1000); system("CLS"); } if (number == point) { cout << "Random number: " << random << "\t\t\t\t\t\t\tPoint: "<< point; cout << "\nCongratulations\n"; life++; point++; Sleep(500); system("CLS"); } else { cout << "Random number: " << random << "\t\t\t\t\t\t\tPoint: "<< point; life--; if(life <= 0) { system("CLS"); cout << "Your Point: " << point; cout <<"\nGood Bye\n"; break; } else cout << "\nPlease Try Again" << endl; Sleep(500); system("CLS"); } } cout << "1.New Game\n2.Exit"; cout << "\nYour Choice: "; cin >> answer; switch(answer) { case 1: break; case 2: cout <<"good bye"; exit(0); break; default: cout << "wrong choice"; break; } } } thats my code but there is sth wrong.when i write not between 1 and 5 the program will reduce the life 2 point and i will have 1 more life but i cant use it.program goes to the new game exit section directly can you guys help me

13th Mar 2017, 12:09 PM
Furkan Kabak
Furkan Kabak - avatar
4 ответов
0
You check for if(number<1) then if(number==point). I think what you what is to check if(number==random).
13th Mar 2017, 1:31 PM
Veii Xhen
Veii Xhen - avatar
0
lol i dont knoe why did i do that thx guys
13th Mar 2017, 1:33 PM
Furkan Kabak
Furkan Kabak - avatar
0
no i dont want that yeah i figured out that later and changed life-=2 to life-- and it worked well
13th Mar 2017, 2:58 PM
Furkan Kabak
Furkan Kabak - avatar
0
} while (new_game != 1 && new_ what does this line do and its doesnt compile what did you meant by that
14th Mar 2017, 11:12 AM
Furkan Kabak
Furkan Kabak - avatar