Question
Hi guy can someone please look over my code.I know I'm doing something wrong here. I just want to know if if im doing the
Hi guy can someone please look over my code.I know I'm doing something wrong here. I just want to know if if im doing the arrays correctly. This is for C programming
Here the assignment:
***********************************************
** MAIN MENU **
***********************************************
- A) Enter game results
- B) Current Record (# of wins and # of losses and # of ties)
- C) Display ALL results from all games WON
- D) Display ALL results ordered by opponent score from low to high.
- E) Quit
Your program will have a menu similar to the example above. The game results will simply be the score by your team and the score by your opponent. The user will enter a single game result at a time. This assignment requires the use of a 2D array. You will not need the date of the game or the names of the teams. All cases will be written within user defined function. Functions should be used as much as possible.
YOU CANNOT
- Use global variables, in this or any program ever.
- Use goto statement(s), in this or any program ever.
Here my code:
define _CRT_SECURE_NO_WARNING
#include
#include
//Prototypes
void menu();
void title();
int result(int(*arr)[2],int row);
void record(int(*arr)[2], int row);
void winningNumber(int(*arr)[2], int row);
void displayAllScore(int arr[][2],int row);
int main(){
//Varibales.
menu();
title();
int numbers[100][2];
int count = 0;
char r;
menu();
printf("Please enter your choice:"); //User enter their choices.
scanf("%c", &r);
while (r != 'E') { //While loop with switch statement.
switch (r) {
case 'A': //Chooses enter game results.
count = result(numbers,count);
break;
case 'B': //Current Record
record(numbers, count);
break;
case 'C': //Winning game results
winningNumber(numbers, count);
break;
case 'D'://Results of other time.
displayAllScore(numbers,count);
break;
default:
break;
}
printf(" ");
menu();
printf("Please enter your choice:");
scanf(" %c", &r);
}
return 0;
}
void title() {
printf(" **** Main Menu **** ");
}
void menu() { //Menu will display on void menu
printf("A)Enter all game results B) Current Record (# of wins and # of losses and # of ties) C) Display ALL results from all games WON D) Display ALL results ordered by opponent score from low to high. E) Quit ");
}
int result(int (*arr)[2],int row) { //user entry data.
printf("Enter your team score: ");
scanf("%d", &arr[row][0]);
printf("Enter other team score: ");
scanf("%d", &arr[row][1]);
return row+=1;
}
void record(int(*arr)[2], int row) { //The record for the game.
int numOfWins = 0, numOfLoss = 0, numOfTies = 0; //The number of game won or lose.
for (int i = 0; i < row; i++) {
if (arr[i][0] > arr[i][1]) { //If statement use for the winner of game.
numOfWins += 1;
}
else if (arr[i][0] < arr[i][1]) { // number that are lose.
numOfLoss += 1;
}
else {
numOfTies += 1; //number that are tied.
}
}
printf(" %d of wins and %d of losses and %d of ties ", numOfWins, numOfLoss, numOfTies); //The result message.
}
void winningNumber(int(*arr)[2], int row) {
printf(" YourScore OtherTeamScore "); //The winning results.
for (int i = 0; i < row; i++) {
if (arr[i][0] > arr[i][1]) {
printf(" %d %d ", arr[i][0], arr[i][1]);
}
}
}
void displayAllScore(int arr[][2],int row) { //This will display all score thoughout the program.
for (int i = 0; i for (int j= i + 1; j if (arr[i][1]>arr[j][1]) { int temp = arr[i][0]; int temp2 = arr[i][1]; arr[i][0] = arr[j][0]; arr[i][1] = arr[j][1]; arr[j][0] = temp; arr[j][1] = temp2; } } } printf(" YourScore OtherTeamScore "); //The score of the team and other team. for (int i = 0; i < row; i++) { for (int j = 0; j < 2; j++) { printf("%d", arr[i][j]); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started