+ 2

It shows errors, what's the problem?

#include <iostream> using namespace std; int main() { int number; number>=15; int users number; cout<<"enter your number"<<endl;cin>>users number; if (number>users number){cout<<"you lose soos";} else{cout<<"you win!";} return 0; }

6th Feb 2018, 7:16 AM
Dokko Krash
Dokko Krash - avatar
5 Réponses
+ 7
// Modifying your code: #include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() { srand(time (0)); int number = 15 + rand() % 30; int users_number; cout<<"enter your number : "; cin>>users_number; if (number>users number) cout<<"you lose soos"; else cout<<"you win!"; return 0; }
6th Feb 2018, 8:02 AM
Hatsy Rei
Hatsy Rei - avatar
+ 6
So you want number to be some random number which is greater than or equal to 15? E.g. #include <cstdlib> #include <ctime> int main() { srand(time(0)); number = 15 + (rand() % 30); } This way, number would be a random number from a range of 15 to 44 (15+29).
6th Feb 2018, 8:00 AM
Hatsy Rei
Hatsy Rei - avatar
+ 4
number >= 15; returns a boolean value to nowhere. (you probably mean number = 15; ?) A variable name cannot contain whitespaces, i.e. "users number" should be "users_number". Cout and cin statements should be separated. cout << "something"; cin >> something.
6th Feb 2018, 7:23 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
thank you. that's exactly what I wanted
6th Feb 2018, 8:03 AM
Dokko Krash
Dokko Krash - avatar
0
thanks! modified it and it worked! but I wanted "number" to be more than or equal to 15
6th Feb 2018, 7:29 AM
Dokko Krash
Dokko Krash - avatar