Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have two problems within this program, I would be very grateful if someone help me out.. 1- How can I display both wins and

I have two problems within this program, I would be very grateful if someone help me out..

1- How can I display both wins and ties calculated percentage with one decimal? I have tried but the result is either 0 or 100 every time.

2- I don't know why my program runs twice with the error msg coming in the second run.

#define _CRT_SECURE_NO_WARNINGS #include #include #include #include // File: main.c // Programming Project: #3 // Assignment: 3 // Programmer: Abdulmalik Basulayb // Date 03/4/2019 // University: McMurry University // Course: COSC 1340 01 Spring 2019 // Instructor: Mr. Brozovic // Compiler: Visual Studio // Program: Rock, paper, scissors

int main(void) { printf(" "); printf("\tRock-Paper-Scissors Program"); printf("\tBy Abdulmalik Basulayb "); printf(" "); printf("\tCourse: COSC 1340 01 \t\tSpring 2019 "); printf(" "); printf("\tGame instructions ==>\to Rock Smashes Scissors!\to Paper Covers Rock!\to Scissors Cuts Paper! "); printf(" "); printf("\tPlease press ENTER to start the game"); getchar();

int r = 0, p = 1, s = 2; int gp = 0; //Game played int u = 0; // User wins int cs = 0; // Computer wins int t = 0; // tie int c; int cwr; //Computer Win rate int uwr; //User Win rate int tr; //Tie rate

char choice; srand(1923); //(unsigned int)time(NULL));

do { printf("\tLet's play Rock-Paper-Scissors! "); printf("\t\tR - Select Rock "); printf("\t\tP - Select Paper "); printf("\t\tS - Select Scissors "); printf("\t\tx - Exit Game "); printf(" \t\t==> "); scanf("%c", &choice); c = rand() % 3 + 1; (choice) = (char)toupper(choice);

switch (choice) { case 'R': r = 0; if (c == 0) { printf(" "); printf("\t\tYou played Rock"); printf("/t\tComputer played Rock "); printf("\t\tWinner is ==> it's a TIE! "); t = t + 1; gp = gp + 1; } else if (c == 1) { printf(" "); printf("\t\tYou played Rock"); printf("\t\tComputer played Paper "); printf("\t\tWinner is ==> Computer! "); cs = cs + 1; gp = gp + 1; } else{ printf(" "); printf("\t\tYou played Rock"); printf("\t\tComputer played scissors "); printf("\t\tWinners is ==> You! "); u = u + 1; gp = gp + 1; } break;

case 'P': p = 1; if (c == 1) { printf(" "); printf("\t\tYou played Paper"); printf("\tComputer played Paper "); printf("\t\tWinner is ==> It's a TIE! "); t++; gp++; } else if (c == 2) { printf(" "); printf("\t\tYou played Paper"); printf("\tComputer played Scissors "); printf("\t\tWinner is ==> Computer! "); cs = cs + 1; gp = gp + 1; } else { printf(" "); printf("\t\tYou played Paper"); printf("\tComputer played Rock "); printf("\t\tWinner is ==> You! "); u = u + 1; gp = gp + 1; } break;

case 'S': s = 2; if (c == 2) { printf(" "); printf("\t\tYou played Scissors"); printf("\tComputer played Scissors "); printf("\t\tWinner is ==> It's a TIE! "); t = t + 1; gp = gp + 1; } else if (c == 1) { printf(" "); printf("\t\tYou played Scissors"); printf("\tComputer played Paper "); printf("\t\tWinner is ==> You! "); u = u + 1; gp = gp + 1; } else { printf(" "); printf("\t\tYou played Scissors"); printf("\tComputer played Rock "); printf("\t\tWinner is ==> Computer! "); cs = cs + 1; gp = gp + 1; } break; case 'X': break; default: printf(" "); printf("\t\tWrong answer! "); printf(" "); break; } } while (choice != 'X'); cwr = (cs / gp) * (100); uwr = (u / gp) * (100); tr = (t / gp) * (100);

printf("\t\t %d games were played", gp); printf("\t\t You won %d games for %2d", u, uwr); printf("\t\t Computer won %d games for %2d", cs, cwr); printf("\t\t Tied %d games for %2d", t, tr);

return 0; }

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

Beginning C# 2005 Databases

Authors: Karli Watson

1st Edition

0470044063, 978-0470044063

More Books

Students also viewed these Databases questions

Question

Explain the various techniques of Management Development.

Answered: 1 week ago