Menu
support@nursinghomework.org
+1 714-215-3097

(Solved) : Two Problems Within Program Would Grateful Someone Help 1 Display Wins Ties Calculated Pe Q35556565

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

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

2- I don’t know why my program runs twice with the error msgcoming in the second run.

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <ctype.h>
// 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(“n”);
   printf(“tRock-Paper-Scissors Program”);
   printf(“tBy Abdulmalik Basulaybnn”);
   printf(“n”);
   printf(“tCourse: COSC 1340 01 ttSpring2019n”);
   printf(“nn”);
   printf(“tGame instructions ==>to Rock SmashesScissors!to Paper Covers Rock!to Scissors Cuts Paper!n”);
   printf(“nn”);
   printf(“tPlease press ENTER to start thegame”);
   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);   //(unsignedint)time(NULL));

  

   do {
       printf(“tLet’s playRock-Paper-Scissors!nn”);
       printf(“ttR – SelectRockn”);
       printf(“ttP – SelectPapern”);
       printf(“ttS – SelectScissorsn”);
       printf(“ttx – ExitGamen”);
       printf(“ntt==> “);
       scanf(“%c”, &choice);
       c = rand() % 3 + 1;
       (choice) =(char)toupper(choice);

       switch (choice) {
       case ‘R’:
           r = 0;
           if (c == 0){
              printf(“n”);
              printf(“ttYou played Rock”);
              printf(“/ttComputer played Rocknn”);
              printf(“ttWinner is ==> it’s aTIE!nn”);
                  t = t + 1;
                  gp = gp + 1;
              }
             
              else if (c == 1) {
                  printf(“n”);
                  printf(“ttYou playedRock”);
                  printf(“ttComputer playedPapernn”);
                  printf(“ttWinner is ==>Computer!nn”);
                  cs = cs + 1;
                  gp = gp + 1;
              }
              else{
                  printf(“n”);
                  printf(“ttYou playedRock”);
                  printf(“ttComputer playedscissorsnn”);
                  printf(“ttWinners is ==>You!nn”);
                  u = u + 1;
                  gp = gp + 1;
              }
          
           break;

       case ‘P’:
           p = 1;
           if (c == 1){
              printf(“n”);
              printf(“ttYou played Paper”);
              printf(“tComputer played Papernn”);
              printf(“ttWinner is ==> It’s aTIE!nn”);
              t++;
              gp++;
           }
              else if (c == 2) {
                  printf(“n”);
                  printf(“ttYou playedPaper”);
                  printf(“tComputer playedScissorsnn”);
                  printf(“ttWinner is ==>Computer!nn”);
                  cs = cs + 1;
                  gp = gp + 1;
              }
              else {
                  printf(“n”);
                  printf(“ttYou playedPaper”);
                  printf(“tComputer playedRocknn”);
                  printf(“ttWinner is ==>You!nn”);
                  u = u + 1;
                  gp = gp + 1;
              }
           break;

       case ‘S’:
           s = 2;
           if (c == 2){
              printf(“n”);
              printf(“ttYou played Scissors”);
              printf(“tComputer played Scissorsnn”);
              printf(“ttWinner is ==> It’s aTIE!nn”);
                  t = t + 1;
                  gp = gp + 1;
              }
              else if (c == 1) {
                  printf(“n”);
                  printf(“ttYou playedScissors”);
                  printf(“tComputer playedPapernn”);
                  printf(“ttWinner is ==>You!nn”);
                  u = u + 1;
                  gp = gp + 1;
              }
              else {
                  printf(“n”);
                  printf(“ttYou playedScissors”);
                  printf(“tComputer playedRocknn”);
                  printf(“ttWinner is ==>Computer!nn”);
                  cs = cs + 1;
                  gp = gp + 1;
              }
          
           break;
       case ‘X’:
           break;
       default:
          printf(“n”);
          printf(“ttWrong answer!n”);
          printf(“n”);
           break;
       }
      
   } while (choice != ‘X’);
   cwr = (cs / gp) * (100);
   uwr = (u / gp) * (100);
   tr = (t / gp) * (100);

   printf(“ttn%d games were played”, gp);
   printf(“ttnYou won %d games for %2d”, u,uwr);
   printf(“ttnComputer won %d games for %2d”, cs,cwr);
   printf(“ttnTied %d games for %2d”, t, tr);

   return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *