Homework in c++ [on hold]
up vote
-2
down vote
favorite
(Guess the Number) Write a program in c++ that plays the game of “guess the number” as follows: Your program should include a function (generateNum) that chooses the number to be guessed by selecting an integer at random in the range 1 to 1000. Every time when the user entered a number, the program will narrow down the range in which the random number contains. The user is only given 10 chances to guess the number. At the end of program, ask if the user would like to play the game again.
The output should be like following:
- Guess a number between 0 to 100 : 50
- Guess a number between 50 to 100 : 70
... - Guess a number between 50 to 55 : 53
You lost, the number is 54!
Do you want to play again? (y/n)
my answer :
int main() {
int input,randomnumber;
randomnumber= 1 + rand () % 1000;
cout<<randomnumber<<endl;
cout<<"Guess the number"<<endl;
cin>>input;
while(input!=randomnumber){
if(input>randomnumber){
cout<<"The number is lower"<<endl;
}
else if(input<randomnumber){
cout<<"The number is higher"<<endl;
}
cout<<"Guess the number"<<endl;
cin>>input;
}
cout<<"Congratulation"<<endl;
return 0;
}
is it correct ??
c++ beginner
New contributor
put on hold as off-topic by πάντα ῥεῖ, Malachi♦ 1 hour ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Malachi
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
up vote
-2
down vote
favorite
(Guess the Number) Write a program in c++ that plays the game of “guess the number” as follows: Your program should include a function (generateNum) that chooses the number to be guessed by selecting an integer at random in the range 1 to 1000. Every time when the user entered a number, the program will narrow down the range in which the random number contains. The user is only given 10 chances to guess the number. At the end of program, ask if the user would like to play the game again.
The output should be like following:
- Guess a number between 0 to 100 : 50
- Guess a number between 50 to 100 : 70
... - Guess a number between 50 to 55 : 53
You lost, the number is 54!
Do you want to play again? (y/n)
my answer :
int main() {
int input,randomnumber;
randomnumber= 1 + rand () % 1000;
cout<<randomnumber<<endl;
cout<<"Guess the number"<<endl;
cin>>input;
while(input!=randomnumber){
if(input>randomnumber){
cout<<"The number is lower"<<endl;
}
else if(input<randomnumber){
cout<<"The number is higher"<<endl;
}
cout<<"Guess the number"<<endl;
cin>>input;
}
cout<<"Congratulation"<<endl;
return 0;
}
is it correct ??
c++ beginner
New contributor
put on hold as off-topic by πάντα ῥεῖ, Malachi♦ 1 hour ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Malachi
If this question can be reworded to fit the rules in the help center, please edit the question.
1
What did you observe when testing your program?
– πάντα ῥεῖ
1 hour ago
Welcome to Code Review. Code is expected to already work as intended, so your question "is it correct" isn't very convincing that your program works correctly. Also, your posted (non-)answer is a feature request, which are off-topic on Code Review. Please have a look at our help center and edit your question accordingly.
– Zeta
1 hour ago
Actually i am trying to get the same output as mentioned in my post, I tried to get it but this the point i reached . I am sure it is not the correct answer for this question . Hopefully , if some one can help me
– ابو محمد
1 hour ago
Thank you so much
– ابو محمد
51 mins ago
add a comment |
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
(Guess the Number) Write a program in c++ that plays the game of “guess the number” as follows: Your program should include a function (generateNum) that chooses the number to be guessed by selecting an integer at random in the range 1 to 1000. Every time when the user entered a number, the program will narrow down the range in which the random number contains. The user is only given 10 chances to guess the number. At the end of program, ask if the user would like to play the game again.
The output should be like following:
- Guess a number between 0 to 100 : 50
- Guess a number between 50 to 100 : 70
... - Guess a number between 50 to 55 : 53
You lost, the number is 54!
Do you want to play again? (y/n)
my answer :
int main() {
int input,randomnumber;
randomnumber= 1 + rand () % 1000;
cout<<randomnumber<<endl;
cout<<"Guess the number"<<endl;
cin>>input;
while(input!=randomnumber){
if(input>randomnumber){
cout<<"The number is lower"<<endl;
}
else if(input<randomnumber){
cout<<"The number is higher"<<endl;
}
cout<<"Guess the number"<<endl;
cin>>input;
}
cout<<"Congratulation"<<endl;
return 0;
}
is it correct ??
c++ beginner
New contributor
(Guess the Number) Write a program in c++ that plays the game of “guess the number” as follows: Your program should include a function (generateNum) that chooses the number to be guessed by selecting an integer at random in the range 1 to 1000. Every time when the user entered a number, the program will narrow down the range in which the random number contains. The user is only given 10 chances to guess the number. At the end of program, ask if the user would like to play the game again.
The output should be like following:
- Guess a number between 0 to 100 : 50
- Guess a number between 50 to 100 : 70
... - Guess a number between 50 to 55 : 53
You lost, the number is 54!
Do you want to play again? (y/n)
my answer :
int main() {
int input,randomnumber;
randomnumber= 1 + rand () % 1000;
cout<<randomnumber<<endl;
cout<<"Guess the number"<<endl;
cin>>input;
while(input!=randomnumber){
if(input>randomnumber){
cout<<"The number is lower"<<endl;
}
else if(input<randomnumber){
cout<<"The number is higher"<<endl;
}
cout<<"Guess the number"<<endl;
cin>>input;
}
cout<<"Congratulation"<<endl;
return 0;
}
is it correct ??
c++ beginner
c++ beginner
New contributor
New contributor
edited 1 hour ago
πάντα ῥεῖ
3,87531328
3,87531328
New contributor
asked 1 hour ago
ابو محمد
1
1
New contributor
New contributor
put on hold as off-topic by πάντα ῥεῖ, Malachi♦ 1 hour ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Malachi
If this question can be reworded to fit the rules in the help center, please edit the question.
put on hold as off-topic by πάντα ῥεῖ, Malachi♦ 1 hour ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Malachi
If this question can be reworded to fit the rules in the help center, please edit the question.
1
What did you observe when testing your program?
– πάντα ῥεῖ
1 hour ago
Welcome to Code Review. Code is expected to already work as intended, so your question "is it correct" isn't very convincing that your program works correctly. Also, your posted (non-)answer is a feature request, which are off-topic on Code Review. Please have a look at our help center and edit your question accordingly.
– Zeta
1 hour ago
Actually i am trying to get the same output as mentioned in my post, I tried to get it but this the point i reached . I am sure it is not the correct answer for this question . Hopefully , if some one can help me
– ابو محمد
1 hour ago
Thank you so much
– ابو محمد
51 mins ago
add a comment |
1
What did you observe when testing your program?
– πάντα ῥεῖ
1 hour ago
Welcome to Code Review. Code is expected to already work as intended, so your question "is it correct" isn't very convincing that your program works correctly. Also, your posted (non-)answer is a feature request, which are off-topic on Code Review. Please have a look at our help center and edit your question accordingly.
– Zeta
1 hour ago
Actually i am trying to get the same output as mentioned in my post, I tried to get it but this the point i reached . I am sure it is not the correct answer for this question . Hopefully , if some one can help me
– ابو محمد
1 hour ago
Thank you so much
– ابو محمد
51 mins ago
1
1
What did you observe when testing your program?
– πάντα ῥεῖ
1 hour ago
What did you observe when testing your program?
– πάντα ῥεῖ
1 hour ago
Welcome to Code Review. Code is expected to already work as intended, so your question "is it correct" isn't very convincing that your program works correctly. Also, your posted (non-)answer is a feature request, which are off-topic on Code Review. Please have a look at our help center and edit your question accordingly.
– Zeta
1 hour ago
Welcome to Code Review. Code is expected to already work as intended, so your question "is it correct" isn't very convincing that your program works correctly. Also, your posted (non-)answer is a feature request, which are off-topic on Code Review. Please have a look at our help center and edit your question accordingly.
– Zeta
1 hour ago
Actually i am trying to get the same output as mentioned in my post, I tried to get it but this the point i reached . I am sure it is not the correct answer for this question . Hopefully , if some one can help me
– ابو محمد
1 hour ago
Actually i am trying to get the same output as mentioned in my post, I tried to get it but this the point i reached . I am sure it is not the correct answer for this question . Hopefully , if some one can help me
– ابو محمد
1 hour ago
Thank you so much
– ابو محمد
51 mins ago
Thank you so much
– ابو محمد
51 mins ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
1
What did you observe when testing your program?
– πάντα ῥεῖ
1 hour ago
Welcome to Code Review. Code is expected to already work as intended, so your question "is it correct" isn't very convincing that your program works correctly. Also, your posted (non-)answer is a feature request, which are off-topic on Code Review. Please have a look at our help center and edit your question accordingly.
– Zeta
1 hour ago
Actually i am trying to get the same output as mentioned in my post, I tried to get it but this the point i reached . I am sure it is not the correct answer for this question . Hopefully , if some one can help me
– ابو محمد
1 hour ago
Thank you so much
– ابو محمد
51 mins ago