Answer to Question #193854 in C++ for Shuvo

Question #193854

Let us consider a guessing game in which the computer picks a random two- digit number in the range from 0 to 99 and asks the user to guess the number. After each guess, the computer lets the player know how many digits of guessed numbers match the correct number. If the guessed number matches the correct number, the computer lets the player know the number of guesses the player made.

1. The program accepts only the positive numbers, i.e., the acceptable range of numbers is 0 to 99 inclusive.

2. The player tries to guess the number computer picked.

3.The program should be robust against both incorrect numbers and non-numeric char- acter (tokens) input.

4.The program must keep count of number of guesses.

5.When user enters the correct guess, the program reports the number of guesses the player made.


1
Expert's answer
2021-05-18T03:00:21-0400
#include<iostream>
#include<time.h>
using namespace std;

int main(){
  srand(time(NULL));
  int num=rand()%100;
  int u_no;
  int attempts{0};
  int digit{0};
  do{
    digit =0;
    std::cout<<"enter the number";
    std::cin>>u_no;
    if(u_no/10 == num/10 || u_no/10== num%10)
      digit=digit+1;
    if(u_no/10 != u_no%10 && u_no%10 == num/10 || u_no/10!= u_no%10 && u_no%10 == num%10)
      digit=digit+1;
    std::cout<< "Guass the number"<<digit<<std::endl;
    attempts=attempts+1;
  }
  while(u_no != num);
  std::cout<<"The number of attempts to guess the number was"<<attempts;
  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog