Question

C++ Visual Studios Your program will attempt to guess a number that the user is thinking...

C++ Visual Studios

Your program will attempt to guess a number that the user is thinking of within the range [1, 20) (1 inclusive 20 exclusive). Your program will have 5 tries and each time the user should be able to tell your program if it is either correct, high, or low. If your program attempts 5 times but is not told that it is correct on the 5th try you should output "You cheated...". Otherwise your program should always be able to guess the correct answer if the user plays the game properly.

In this program you are required to write a function that takes a number (int) as a parameter and outputs the prompt to the user that guesses that number (tells the user "Is this your number: <guess>") and shows them a menu that explains how to enter correct, high, or low. You may use the method that we used in class, where the user enters a number corresponding to their selection of high, low, or correct. (this function should be a int function that returns the users selection)

The next function that is required is the function that is used to calculate the next guess after being told that the previous guess was either high or low. (I will leave the design of this function up to you)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>
#include<math.h>
#include <stdlib.h>

int N; //number of values in file


//function computing the sum of squares
double E(double x[],int size) {
double summSquare = 0;

for(int i=0;i<size;i++){
summSquare = summSquare + x[i]*x[i];
}

return summSquare;
}


// function computing normcorr
double normcorr(double x[],double y[],int size) {

double productSum = 0;
double squarerootProduct = sqrt(E(x,size))*sqrt(E(y,size));
for(int i=0;i<size;i++){
productSum = productSum + x[i]*y[i];
}

return (1/squarerootProduct)*productSum;
}


// function reading file up-to EOF
double *readFile(char *fileName) {

double X[10000];
FILE *fpr;
char str[200];
fpr = fopen(fileName, "r");

if (fpr == NULL)
{
puts("Could not open file");
}
int i = 0;
int sizeX;
while(1)
{

if(fgets(str, 10, fpr) ==NULL)
break;
else{
X[i] = atof(str);
i++;
}


}
sizeX = i;
fclose(fpr);
for(int i=0;i<sizeX;i++){
}

// allocating memory dynamically since size of file is not known prior
double *fileContents;
fileContents = (double *)malloc(sizeof(double)*sizeX);

for(int i=0;i<sizeX;i++){
fileContents[i] = X[i];
}
N = sizeX;
return fileContents;
}

// function cater for cases when sizes of 2 files is not the same,
int getMinimumSize(int x, int y)
{
return (x < y) ? x : y;
}

int main(){

double *contentOfReferenceECG = readFile("ReferenceECG.txt");
int sizeReferenceECG = N;

double *contentOfNormalECG = readFile("NormalECG.txt");
int sizeNormalECG = N;

double *contentOfAbnormalECG = readFile("AbnormalECG.txt");
int sizeAbnormalECG = N;

printf("\nReferenceECG: ");
for(int i=0;i<sizeReferenceECG ;i++){
printf("%lf ",contentOfReferenceECG[i]);
}

printf("\nNormalECG: ");
for(int i=0;i<sizeNormalECG;i++){
printf("%lf ",contentOfNormalECG[i]);
}

printf("\nAbnormalECG: ");
for(int i=0;i<sizeAbnormalECG;i++){
printf("%lf ",contentOfAbnormalECG [i]);
}

int size;

size = getMinimumSize(sizeReferenceECG,sizeNormalECG);
printf("\n normcorr(ReferenceECG,NormalECG) = %0.2lf",normcorr(contentOfReferenceECG,contentOfNormalECG,size));

size = getMinimumSize(sizeReferenceECG,sizeAbnormalECG);
printf("\n normcorr(ReferenceECG,AbnormalECG) = %0.2lf",normcorr(contentOfReferenceECG,contentOfAbnormalECG,size));

return 0;}

Add a comment
Know the answer?
Add Answer to:
C++ Visual Studios Your program will attempt to guess a number that the user is thinking...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Java Program to allow a user to guess a person’s age until they get...

    Write a Java Program to allow a user to guess a person’s age until they get it correct. After each guess, the user must be told whether their guess was correct, too high or too low. Once the user enters the correct age, the program must display how many guesses it took the user to guess the correct age.

  • Write a Java application program that plays a number guessing game with the user. In the...

    Write a Java application program that plays a number guessing game with the user. In the starter code that you are given to help you begin the project, you will find the following lines of code: Random generator = args.length == 0 ? new Random() :                    new Random(Integer.parseInt(args[0])); int secret = generator.nextInt(100); You must keep these lines of code in your program. If you delete these lines, or if you change thse lines in any way, then your program...

  • Write a C++ program using "for" loop to allow user to guess a certain number say...

    Write a C++ program using "for" loop to allow user to guess a certain number say 55. The loop will end after 5 guesses or if he guesses the right number, which ever comes first. If user enters a number greater than 55, your program should print "You entered a bigger number". If user enters a number smaller than 55, your program should print "You entered a smaller number". If user enters 55 in less than 5 attempt, your program...

  • Guess the number! You will create a program that will ask the user to guess a...

    Guess the number! You will create a program that will ask the user to guess a number between 1 and 10. The pseudocode is below. Be sure to import random at the beginning of your code and use a comment block explaining what your program does #Guess the number week 4 #Name: #Date: #Random number, loop while true #ask user for number. #if number is too high or too low, tell user, if they guessed it break out of loop...

  • Write a program that prompts the user for an integer that the player (maybe the user,...

    Write a program that prompts the user for an integer that the player (maybe the user, maybe someone else) will try to guess. If the player's guess is higher than the target number, the program should display "too high" If the user's guess is lower than the target number, the program should display "too low" The program should use a loop that repeats until the user correctly guesses the number. Then the program should print how many guesses it took....

  • Java code Guessing Game Refinement. (The user thinks of a number and the program guesses it)...

    Java code Guessing Game Refinement. (The user thinks of a number and the program guesses it) Program should be able to guess correctly in 7 tries or lower. Initialize a variable that represents the lowest possible number to 0 (what type should this be?) Initialize a variable that represent the highest possible number to 100 (what type should this be?) Initialize a Boolean variable that represents if we’ve achieved the correct guess to false Initialize a variable in which to...

  • Write a C program that generates a random number between 0 and 50. Then, the program...

    Write a C program that generates a random number between 0 and 50. Then, the program prompts for guesses until the user is correct, or has made 10 wrong guesses. After each guess, the program indicates whether the guess was too high, too low, or correct. Once the round has ended, either by a correct guess or by using up the 10 guesses, the program displays the current status.

  • Guess My Number Create a mul5-func5on version of the Guess My Number game. Your game should...

    Guess My Number Create a mul5-func5on version of the Guess My Number game. Your game should generate a random number between 1 and 99, ask the user for a guess, and respond to each guess with correct, too high, or too low as needed. Once the user guesses the number correctly, report how many guesses it took and ask if they want to play again. You need to have at least the following three func5ons: displayInstruc5ons — no inputs, displays...

  • Hello, Could you please explain how I would complete this program with input validation to ensure...

    Hello, Could you please explain how I would complete this program with input validation to ensure that an error message will not appear if the user enters something other than an integer that is not 1-100 and later if they enter anything other than yes and no? Here is the program: Write a program that plays the Hi-Lo guessing game with numbers. The program should pick a random number between 1 and 100 (inclusive), then repeatedly promt the user to...

  • How can I do this program complete with input validation so that the computer prompts the...

    How can I do this program complete with input validation so that the computer prompts the user to enter a number 0 through 100 if he/she guesses anything lower than 0, a floating point number, or other characters? And later, prompts the user to enter yes or no if he/she enters anything else when the program prompts the user to play again? Write a program that plays the Hi-Lo guessing game with numbers. The program should pick a random number...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT