Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Could someone please tell me why this C code will not run? The errors I am receiving are: #include #include #include #define ADD 1 #define

Could someone please tell me why this C code will not run? The errors I am receiving are:

image text in transcribed

#include #include #include

#define ADD 1 #define MULT 2

// Function prototypes double arithGame(int max, int quantity, int op); double guessGame(int max); int numDigits(int number); int numPoints(double timesec);

int main() { // Seed random number generator srand(time(0));

// Initialize scores double arithScore = 0; double guessScore = 0;

// Main menu loop int option; do { printf("1) Play Arithmetic Game "); printf("2) Play Guessing Game "); printf("3) Print Score "); printf("4) Quit "); printf("Enter your choice: "); scanf("%d", &option);

switch (option) { case 1: { // Arithmetic game int max, quantity, op; printf("Enter the maximum value: "); scanf("%d", &max); printf("Enter the number of questions: "); scanf("%d", &quantity); printf("Enter 1 for addition, 2 for multiplication: "); scanf("%d", &op); double time = arithGame(max, quantity, op); printf("You took %.2lf seconds for %d problems. ", time, quantity); double score = (time + 5 * (quantity - op)) / quantity; arithScore += numPoints(score); break; } case 2: { // Guessing game int max; printf("Enter the maximum number: "); scanf("%d", &max); double time = guessGame(max); printf("You took %.2lf seconds to guess the number. ", time); double score = time / (2 * numDigits(max)); guessScore += numPoints(score); break; } case 3: { // Print scores printf("Arithmetic score: %d ", (int)arithScore); printf("Guessing score: %d ", (int)guessScore); break; } case 4: // Quit program break; default: printf("Invalid choice. Please enter a number between 1 and 4. "); } printf(" "); } while (option != 4);

return 0; }

// Returns the number of digits in number. int numDigits(int number) { int digits = 0; while (number != 0) { number /= 10; digits++; } return digits; }

// Returns the number of points the user has earned based // on time. int numPoints(double timesec) { if (timesec

// This function gives the user quantity arithmetic // questions, where each operand ranges from double arithGame(int max, int quantity, int op) { int i; double start, end, time, penalty = 0.0, result, answer; for (i = 0; i

double guessGame(int max) { double start, end, time, guess; int number = rand() % max + 1; int digits = numDigits(max); printf("I'm thinking of a number between 1 and %d. Guess it! ", max); do { start = time(0); scanf("%lf", &guess); end = time(0); if (guess number) { printf("Too high. "); } time += end - start; } while (guess != number); return time / (2.0 * digits); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Security

Authors: Alfred Basta, Melissa Zgola

1st Edition

1435453905, 978-1435453906

Students also viewed these Databases questions