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:




  1. Guess a number between 0 to 100 : 50

  2. Guess a number between 50 to 100 : 70
    ...

  3. 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 ??










share|improve this question









New contributor




ابو محمد is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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















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:




  1. Guess a number between 0 to 100 : 50

  2. Guess a number between 50 to 100 : 70
    ...

  3. 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 ??










share|improve this question









New contributor




ابو محمد is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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













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:




  1. Guess a number between 0 to 100 : 50

  2. Guess a number between 50 to 100 : 70
    ...

  3. 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 ??










share|improve this question









New contributor




ابو محمد is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











(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:




  1. Guess a number between 0 to 100 : 50

  2. Guess a number between 50 to 100 : 70
    ...

  3. 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






share|improve this question









New contributor




ابو محمد is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




ابو محمد is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 1 hour ago









πάντα ῥεῖ

3,87531328




3,87531328






New contributor




ابو محمد is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 1 hour ago









ابو محمد

1




1




New contributor




ابو محمد is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





ابو محمد is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






ابو محمد is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




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














  • 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















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Quarter-circle Tiles

build a pushdown automaton that recognizes the reverse language of a given pushdown automaton?

Mont Emei