Question

In: Computer Science

please fix code #include <stdio.h> #include <stdlib.h> #include <string.h> // function declarations int getValidJerseyNumber(); int getValidRating();...

please fix code

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

// function declarations
int getValidJerseyNumber();
int getValidRating();
int main()
{
// declaring variables
int size = 5;
int jerseyNo[size];
int rating[size];
int i = 0, jno, rate;
char option;

/* Getting the inputs entered by the user
* and populate the values into arrays
*/
for (i = 0; i < size; i++)
{
printf("Enter player %d's jersey number:", i + 1);
jerseyNo[i] = getValidJerseyNumber();

printf("Enter player %d's rating:\n", i + 1);
rating[i] = getValidRating();
}

/* This while loop continues to execute
* until the user enters a valid option or 'q/Q'
*/
while (1)
{
// displaying the menu
printf("\nMENU\n");
printf("u - Update player rating\n");
printf("a - Output players above a rating\n");
printf("r - Replace player\n");
printf("o - Output roster\n");
printf("q - Quit\n");
// getting the choice entered by the user
printf("Choose an option:");
scanf("%c", &option);

// Based on the user choice the corresponding case will be executed
switch (option)
{
case 'u':
case 'U':
{
int flag = 0;
printf("Enter a jersey number:");
jno = getValidJerseyNumber();
printf("Enter a new rating for player\n");
rate = getValidRating();
for (i = 0; i < size; i++)
{
if (jerseyNo[i] == jno)
{
rating[i] = rate;
flag = 1;
}
}
if (flag == 0)
{
printf("** Player not found **\n");
}

continue;
}
case 'a':
case 'A':
{

printf("Enter a rating \n");
rate = getValidRating();
printf("Above%d\n", rate);
for (i = 0; i < size; i++)
{
if (rating[i] > rate)
printf("Player %d -- Jersey Number:%d. Rating:%d\n", i + 1, jerseyNo[i],
rating[i]);
}
continue;
}
case 'R':
case 'r':
{
int flag = 0, newjNo;
printf("Enter a jersey number:");
jno = getValidJerseyNumber();
for (i = 0; i < size; i++)
{
if (jerseyNo[i] == jno)
{
printf("Enter a new jersey number:\n");
newjNo = getValidJerseyNumber();
jerseyNo[i] = newjNo;
printf("Enter a rating for the new player:");
rate = getValidRating();
rating[i] = rate;
}
}
continue;
}
case 'o':
case 'O':
{
printf("\nROSTER\n");
for (i = 0; i < size; i++)
{
printf("Player %d -- Jersey Number:%d. Rating:%d\n", i + 1, jerseyNo[i],
rating[i]);
}
continue;
}
case 'Q':
case 'q':
{

break;
}
default:
{
printf("** Invalid Option **\n");
continue;
}
}
break;
}


return 0;
}
// This function will get the valid jersey number from the user
int getValidJerseyNumber()
{
int jerseyNum;
while (1)
{
scanf("%d", &jerseyNum);
if (jerseyNum < 0 || jerseyNum > 99)
{
printf("Invalid must be between 0-99\n");
printf("Re-Enter:\n");

continue;
}
else
{
break;
}
}
return jerseyNum;
}
// This function will get the valid rating from the user
int getValidRating()
{
int rate;
while (1)
{
scanf("%d", &rate);
if (rate < 1 || rate > 9)
{
printf("Invalid must be between 1-9\n");
printf("Re-Enter:\n");

continue;
}
else
{
break;
}
}
return rate;
}

-------------------------------------------------------------

This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balanced team.

(1) Prompt the user to input five pairs of numbers: A player's jersey number (0 - 99) and the player's rating (1 - 9). Store the jersey numbers in one int array and the ratings in another int array. Output these arrays (i.e., output the roster). (3 pts)

Ex:

Enter player 1's jersey number:
84
Enter player 1's rating:
7

Enter player 2's jersey number:
23
Enter player 2's rating:
4

Enter player 3's jersey number:
4
Enter player 3's rating:
5

Enter player 4's jersey number:
30
Enter player 4's rating:
2

Enter player 5's jersey number:
66
Enter player 5's rating:
9

ROSTER
Player 1 -- Jersey number: 84, Rating: 7
Player 2 -- Jersey number: 23, Rating: 4
...

(2) Implement a menu of options for a user to modify the roster. Each option is represented by a single character. The program initially outputs the menu, and outputs the menu after a user chooses an option. The program ends when the user chooses the option to Quit. For this step, the other options do nothing. (2 pt)

Ex:

MENU
u - Update player rating
a - Output players above a rating
r - Replace player
o - Output roster
q - Quit

Choose an option:

(3) Implement the "Output roster" menu option. (1 pt)

Ex:

ROSTER
Player 1 -- Jersey number: 84, Rating: 7
Player 2 -- Jersey number: 23, Rating: 4
...

(4) Implement the "Update player rating" menu option. Prompt the user for a player's jersey number. Prompt again for a new rating for the player, and then change that player's rating. (1 pt)

Ex:

Enter a jersey number:
23
Enter a new rating for player:
6

(5) Implement the "Output players above a rating" menu option. Prompt the user for a rating. Print the jersey number and rating for all players with ratings above the entered value. (2 pts)

Ex:

Enter a rating:
5

ABOVE 5
Player 1 -- Jersey number: 84, Rating: 7
...

(6) Implement the "Replace player" menu option. Prompt the user for the jersey number of the player to replace. If the player is in the roster, then prompt again for a new jersey number and rating. Update the replaced player's jersey number and rating. (2 pts)

Ex:

Enter a jersey number:
4
Enter a new jersey number:
12
Enter a rating for the new player:
8

Solutions

Expert Solution

PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU
PLACE AN EXTRA SPACE WHILE SCANNING FOR INPUT, AS THIS, WILL TERMINATE THE EXISTING SCANNING AND ALLOWS YOU TO ENTER, DUE TO THIS THE MENU ISSUE WAS HAPPENING

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

// function declarations
int getValidJerseyNumber();
int getValidRating();
int main()
{
  // declaring variables
  int size = 5;
  int jerseyNo[size];
  int rating[size];
  int i = 0, jno, rate;
  char option;

  /* Getting the inputs entered by the user
* and populate the values into arrays
*/
  for (i = 0; i < size; i++)
  {
    printf("Enter player %d's jersey number:", i + 1);
    jerseyNo[i] = getValidJerseyNumber();

    printf("Enter player %d's rating:\n", i + 1);
    rating[i] = getValidRating();
  }
  char c;
  /* This while loop continues to execute
* until the user enters a valid option or 'q/Q'
*/
  while (1)
  {
    // displaying the menu
    printf("\nMENU\n");
    printf("u - Update player rating\n");
    printf("a - Output players above a rating\n");
    printf("r - Replace player\n");
    printf("o - Output roster\n");
    printf("q - Quit\n");
    // getting the choice entered by the user
    printf("Choose an option:");
    scanf(" %c", &option);

    // Based on the user choice the corresponding case will be executed
    switch (option)
    {
    case 'u':
    case 'U':
    {
      int flag = 0;
      printf("Enter a jersey number:");
      jno = getValidJerseyNumber();
      printf("Enter a new rating for player\n");
      rate = getValidRating();
      for (i = 0; i < size; i++)
      {
        if (jerseyNo[i] == jno)
        {
          rating[i] = rate;
          flag = 1;
        }
      }
      if (flag == 0)
      {
        printf("** Player not found **\n");
      }

      continue;
    }
    case 'a':
    case 'A':
    {

      printf("Enter a rating \n");
      rate = getValidRating();
      printf("Above%d\n", rate);
      for (i = 0; i < size; i++)
      {
        if (rating[i] > rate)
          printf("Player %d -- Jersey Number:%d. Rating:%d\n", i + 1, jerseyNo[i],
                 rating[i]);
      }
      continue;
    }
    case 'R':
    case 'r':
    {
      int flag = 0, newjNo;
      printf("Enter a jersey number:");
      jno = getValidJerseyNumber();
      for (i = 0; i < size; i++)
      {
        if (jerseyNo[i] == jno)
        {
          printf("Enter a new jersey number:\n");
          newjNo = getValidJerseyNumber();
          jerseyNo[i] = newjNo;
          printf("Enter a rating for the new player:");
          rate = getValidRating();
          rating[i] = rate;
        }
      }
      continue;
    }
    case 'o':
    case 'O':
    {
      printf("\nROSTER\n");
      for (i = 0; i < size; i++)
      {
        printf("Player %d -- Jersey Number:%d. Rating:%d\n", i + 1, jerseyNo[i],
               rating[i]);
      }
      continue;
    }
    case 'Q':
    case 'q':
    {

      break;
    }
    default:
    {
      printf("** Invalid Option **\n");
      continue;
    }
    }
    break;
  }

  return 0;
}
// This function will get the valid jersey number from the user
int getValidJerseyNumber()
{
  int jerseyNum;
  while (1)
  {
    scanf("%d", &jerseyNum);
    if (jerseyNum < 0 || jerseyNum > 99)
    {
      printf("Invalid must be between 0-99\n");
      printf("Re-Enter:\n");

      continue;
    }
    else
    {
      break;
    }
  }
  return jerseyNum;
}
// This function will get the valid rating from the user
int getValidRating()
{
  int rate;
  while (1)
  {
    scanf("%d", &rate);
    if (rate < 1 || rate > 9)
    {
      printf("Invalid must be between 1-9\n");
      printf("Re-Enter:\n");

      continue;
    }
    else
    {
      break;
    }
  }
  return rate;
}

Related Solutions

Please paraphrase this c code #include <stdio.h> #include <stdlib.h> #include <string.h> void sortGrades(int arr[], int size,...
Please paraphrase this c code #include <stdio.h> #include <stdlib.h> #include <string.h> void sortGrades(int arr[], int size, int status, char names[][20]); void printer(int grades[], int size, char names[][20]); void sortNames(char arr[][20], int size, int status, int grades[]); void nameSearch(int grades[], int size, char names[][20]); void numSearch(int grades[], int size, char names[][20]); int main() { int i; int size; int option; do { printf("\n\nInput Number of Students or 0 to exit : "); scanf("%d", &size); if (size == 0) { break; }...
#include <stdlib.h> #include <stdio.h> #include <string.h> void clrScreen(int lines){     int i = 0;     for( i =...
#include <stdlib.h> #include <stdio.h> #include <string.h> void clrScreen(int lines){     int i = 0;     for( i = 0; i < lines; ++i ){         printf("\n");     }     return; } void printRules(void){     printf("\t|*~*~*~*~*~*~*~*~*~ How to Play ~*~*~*~*~*~*~*~*~*~|\n");     printf("\t|   This is a 2 player game. Player 1 enters the   |\n");     printf("\t|   word player 2 has to guess. Player 2 gets a    |\n");     printf("\t|   number of guesses equal to twice the number    |\n");     printf("\t|   of characters. EX: If the word is 'example'    |\n");     printf("\t|   player 2 gets 14 guesses.                      |\n");     printf("\t|*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~|\n");     clrScreen(10);     return; } //------------------------------------------------------------------------------------------------------------ /*...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> int main(int argc, char *argv[]) {     FILE *myFile;...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> int main(int argc, char *argv[]) {     FILE *myFile;     char fname[20];     //int sum = 0;     int i, j, k, tmp =0;     int num = 0;     int mass = 0;     int count = 0;     int fuel = 0;     int total = 0;     int M[1000];     char ch;     char buffer[32];     printf(" Input the filename to be opened : ");     scanf("%s",fname);     myFile = fopen(fname, "r");     if(myFile == NULL)     {         printf("Can't open file\n");     } while(1)     {         ch =...
#include <stdio.h> #include <string.h> #include<stdlib.h> #include<conio.h> struct Bank_Account_Holder { int account_no; char name[80]; int balance; };...
#include <stdio.h> #include <string.h> #include<stdlib.h> #include<conio.h> struct Bank_Account_Holder { int account_no; char name[80]; int balance; }; int n; void accept(struct Bank_Account_Holder[], int); void display(struct Bank_Account_Holder[], int); void save(struct Bank_Account_Holder[], int); void load(struct Bank_Account_Holder[], int); int search(struct Bank_Account_Holder[], int, int); void deposit(struct Bank_Account_Holder[], int, int, int); void withdraw(struct Bank_Account_Holder[], int, int, int); int lowBalenquiry(int,int); void main(void) { clrscr(); struct Bank_Account_Holder data[20]; int choice, account_no, amount, index; printf("NHU Banking System\n\n"); printf("Enter the count of records: "); scanf("%d", &n); accept(data, n); do {...
Please implement the 5 questions in source code: #include <stdio.h> #include <stdlib.h> #include <math.h> int main(...
Please implement the 5 questions in source code: #include <stdio.h> #include <stdlib.h> #include <math.h> int main( int argc, char* argv[] ) { // Size of vectors int n = 10000; // Input vectors double *restrict a; double *restrict b; // Output vector double *restrict c; // Size, in bytes, of each vector size_t bytes = n*sizeof(double); /* Q1: Allocate memory for vector a (10 points)*/ /* Q2: Allocate memory for vector b (10 points)*/ /* Q3: Allocate memory for vector...
Please Work on the commented parts in the code #include <stdio.h> #include <stdlib.h> /* * */...
Please Work on the commented parts in the code #include <stdio.h> #include <stdlib.h> /* * */ void printArray(int *arr, int size){ int i; for( i = 0; i < size; i++) { // Print each element out printf("%d ", *(arr+i)); //Print addresses of each element printf("%p", (arr+i)); //Printing a new line printf("\n"); } } int main() { // Allows user to specify the original array size, stored in variable n1. printf("Enter original array size: "); int n1 = 0; scanf("%d",...
my code is not printing the output #include <stdio.h> #include<stdbool.h> int main(){ // variable declarations   bool...
my code is not printing the output #include <stdio.h> #include<stdbool.h> int main(){ // variable declarations   bool binary[12] = {false,false, false, false,false,false,false,false,false,false,false, false};   int powerTwo[12] = {2048.1028,576, 256, 128, 64, 32, 16, 8 , 4, 2, 1};   int oneZero[9]= {0,0,0,0,0,0,0,0,0};   int tempVal = 0;   double decimal = 0;   int i = 0;   int j = 0;   // Intialization   printf("Starting the CPSC 1011 Decimal to Binary Converter!\n");   printf("Please enter a positive whole number (or EOF to quit): \n");   scanf("%lf", &decimal);   printf("%lf", decimal);...
#include <stdio.h> #include <stdlib.h> int play_game(int *); // Returns 0 if player won, 1 if the...
#include <stdio.h> #include <stdlib.h> int play_game(int *); // Returns 0 if player won, 1 if the computer won, 2 if there is a tie, and -1 if the player decides to quit int menu(int *); // Displays choices to user // Receives score array int main() { srand(42); // Seeding Random with 42 int score[3]; // Array keeping Player, Computer, and Tie Scores score [0] = 0; // Player - initialized to Zero score [1] = 0; // Computer -...
CODE A #include<stdio.h> #include<math.h> #include<stdlib.h> #define PI 3.14159265358979323846 int main(){ int diameter; printf("Enter value of diameter...
CODE A #include<stdio.h> #include<math.h> #include<stdlib.h> #define PI 3.14159265358979323846 int main(){ int diameter; printf("Enter value of diameter between 8 to 60 inches: "); scanf("%d",&diameter); // if(diameter>60 || diameter<=8){ // printf("Error! invalid input"); // exit(0); // } // else{ // float radius = diameter/2; // float volume = (4/3)*PI*radius*radius*radius; // printf("%.2f",volume); // } //check through the while loop if it is valid or in valid while(diameter>60 || diameter<=8){ printf("Invalid input Enter again: "); scanf("%d",&diameter); }    //caluclate the volume of sphere float...
#include <stdio.h> #include <stdlib.h> #include <time.h> void sort(int a[], int size); void printArray(int a[], int size);...
#include <stdio.h> #include <stdlib.h> #include <time.h> void sort(int a[], int size); void printArray(int a[], int size); int main(){ int arraySize, limit, count, srand(time(0)); print f("Enter the size of array\n"); scanf("%d", arraySize); int array[arraySize]; printf("Enter the upper limit\n"); scanf("%d", &limit); count = 0; while(count <= arraySize){ array[count] = (rand() % (limit + 1)); count++; } printArray(array, &arraySize); sort(array, arraySize); printArray(array, arraySize); Return 0; } void printArray(int a[], int size){ int i = 0; printf("Array: ["); while(i < size){ if(i != size...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT