Question

Code a program to reproduce Madame Esmerelda’s clairvoyant test: Mme. Esmerelda conjures up a random number...

Code a program to reproduce Madame Esmerelda’s clairvoyant test: Mme. Esmerelda conjures up a random number 1-10 in her mind and commands the user to guess what it is. If the user’s guess is equal to (remember your double equal sign!) the conjured number, Mme. Esmerelda extends a job offer as a clairvoyant assistant. Add a user-driven loop that allows the user to play repeatedly if desired (but your program should conjure a new random number with every loop iteration).

These steps from my teacher:

//0. create variables for random number and user guess (you have user guess but not the random number variable). Also seed the random number (which you are doing correctly already at the top of your program).

//1. generate a random number and put it in an integer variable. You've seeded the random number but have not actually generated one. Also, the game is not fun if the number to guess is always 5, as you've coded it. It should be random every time.

//2. display greeting and ask user for guess

//3. You may keep your input validation loop here, which is correct, but that is not actually required in this assignment.

//4. now make the decision with a simple if/else:
//if user guess is equal to the random number
//display "that is correct" message
//else
//display "sorry, that is incorrect" message


^We only need one simple if/else in this program.

Homework Answers

Answer #1

If the program is required in C++ please refer the below code snippet.

#include <iostream>
#include <time.h>

int main() {

        //defines range for random number selection.
        int min = 1, max = 10, rcount = 10;
        int rndnum, usernum;
        bool willguess = true;
        char chkwish;
        char nwish[1];
        nwish[0] = 'n';

        while (willguess == true)
        {
                srand(time(0)); //seed to change the random number
                rndnum = (rand() % (max - min) + 1) + min;

                std::cout << "\nGreetings!!.. Can u guess the number?\n";
                std::cin >> usernum;

                //compare the user guess and random number
                if (usernum == rndnum)
                {
                        std::cout << "Perfect!!.. That's correct!\n";
                }
                else
                {
                        std::cout << "Sorry, that is incorrect.\n";
                        std::cout << "Correct guess is:" << rndnum << "\n";
                }

                std::cout << "Do you want to guess another number(y/n)?";
                std::cin >> chkwish;
        
                if (chkwish == nwish[0])
                {
                        willguess = false;
                }

        }               

        return 0;
}

Output Snapshot:

If you need program in C code, please refer the below code snippet.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
typedef enum {  F, T } boolean;

int main() {

        //defines range for random number selection.
        int min = 1, max = 10, rcount = 10;
        int rndnum, usernum;
        boolean willguess = T;
        char chkwish;
        char chr;
        char nwish[1];
        nwish[0] = 'n';

        while (willguess == T)
        {
                srand(time(0)); //seed to change the random number
                rndnum = (rand() % (max - min) + 1) + min;
                
                printf("\nGreetings!!.. Can u guess the number?\n");
                scanf("%d",&usernum);

                //compare the user guess and random number
                if (usernum == rndnum)
                {
                        printf("Perfect!!.. That's correct!\n");
                }
                else
                {
                        printf("Sorry, that is incorrect.\n");
                        printf("Correct guess is:%d\n", rndnum );
                };

                printf("Do you want to guess another number(y/n)?");
                scanf("%c",&chkwish);
                scanf("%c",&chkwish); //repeating to avoid newline char as scanf was skipping
        
                if (chkwish == nwish[0])
                {
                        willguess = F;
                }

        }               

        return 0;
}

Output Snapshot:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
JAVA Write a number guessing game that will generate a random number between 1and 20 and...
JAVA Write a number guessing game that will generate a random number between 1and 20 and ask the user to guess that number. The application should start by telling the user what the app does. You should then create the random number and prompt the user to guess it. You need to limit the number of times that the user can guess to 10 times. If the user guesses the number, display some message that tell them that they did...
Write a c++ program to pull a random number between 1-100 inclusive. Ask the user to...
Write a c++ program to pull a random number between 1-100 inclusive. Ask the user to guess the number. If the random number is higher than the guess, print "Higher". If the random number is less than the guess, print "Lower". If the random number is equal to the quess, print "Correct!". Create a variable to count the number of guesses and intitialize it to zero. int guesses=0; Increase this variable by 1 every time the user enters a new...
Write a program (C language) that will read the number of a month and will print...
Write a program (C language) that will read the number of a month and will print the number of days in the month. Ignore leap years. Use 28 days for February. Have the program runs in a continuous loop, allowing the user to enter a month number, see that number of days, and repeat. Use month number = 0 to exit the loop and the program. Program must meet the following criteria: 1.Your name and the name of the program...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the program title and programmer’s name. Then get the user’s name, and greet the user. • Prompt the user to enter the number of Fibonacci terms to be displayed. Advise the user to enter an integer in the range [1 .. 46]. • Get and validate the user input (n). • Calculate and display all of the Fibonacci numbers up to and including the nth...
Create a C++ program that generates a random number from 1 to 100 using the rand()...
Create a C++ program that generates a random number from 1 to 100 using the rand() function. Give the user a total 5 chances to guess the number. Stop the program and indicate the user guessed the correct number and should be applauded. Also, please find out which guess was the closest to the actual number. For example, if the rand() produces 57 and the user guessed 10, 80, 52, 33 and 44 in their respective turns then print out...
html/php 1. Create an html page (with an html file ending) that contains a form. This...
html/php 1. Create an html page (with an html file ending) that contains a form. This form will accept a number from the user. The form will then send this number to the assignment3.php program by using either GET or POST. 2. The assignment3.php program will read the value in the textbox and place it into the variable "myvalue". The program will then use either a switch statement or IF/THEN/ELSE statement to determine if the value entered is within 10...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts,...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts, it will present a welcome screen. You will ask the user for their first name and what class they are using the program for (remember that this is a string that has spaces in it), then you will print the following message: NAME, welcome to your Magic Number program. I hope it helps you with your CSCI 1410 class! Note that "NAME" and "CSCI...
Write a program to pre-sell a limited number of cinema tickets. Each buyer can buy as...
Write a program to pre-sell a limited number of cinema tickets. Each buyer can buy as many as 4 tickets. No more than 20 tickets can be sold. Implement a program called TicketSeller that prompts the user for the desired number of tickets and then displays the number of remaining tickets. Repeat until all tickets have been sold, and then display the total number of buyers.4 pts Loop     There are currently xxx tickets remaining.     How many tickets would...
Please make a Python program where the computer chooses a number and the player guesses the...
Please make a Python program where the computer chooses a number and the player guesses the number. And at the end, please report the number of attempts. You need an input, a random number, if statement, and a while loop. Please reference the pre-lab document in the Blackboard. Please prepare a Word document that has the Python code and the screen shot of your output. Here is a sample of what the output screen should look like. What is your...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT