Question: I am Programming with C in CodeBlocks. I need help for user input error. For Example say the User inputs a negative number for the

 I am Programming with C in CodeBlocks. I need help for

I am Programming with C in CodeBlocks. I need help for user input error. For Example say the User inputs a negative number for the score my outcome would be for the program to read "Invalid Score. Try again". I tried using if-else statement and even a while loop but kept having issues. Sometimes it would output 8 in for option 3,4. Thank you for your time.

Here is the Error Code I tried Using in function game_result

int num1;

//Team Score Input printf("Your team score: "); scanf("%d", &num1); if (num1 >= 0) { num1=result[count][0]; } else if (num1

//Opponent Team Score Input printf("Opponent team score: "); scanf("%d", &num1); if(num1 >= 0) { num1=result[count][1]; } else if (num1

Here is the Code Without it Running Okay

#include #include

//function prototypes void game_result(int result[10][2], int display[10][2], int count); void current_records(int result[10][2], int count); void display_win(int result[10][2], int count); void display_op(int result[10][2], int display[10][2], int count); void print_Menu();

int main()

{ int choice; int count = 0; int result[10][2]; int display[10][2];

while (choice != 5) { //Function for Menu print_Menu(); scanf(" %d", &choice); switch(choice) { case 1: if (count

//Print Menu void print_Menu() { printf(" ************************************** "); printf("\t\tMain Menu"); printf(" ************************************** "); printf("1) Enter game result "); printf("2) Current Record (# of wins and # of losses and # of ties) "); printf("3) Display all results from Team games won "); printf("4) Display all results ordered by Opponent score from low to high "); printf("5) Exit "); printf("Enter the choice : ");

}

//Provides Game Results void game_result(int result[10][2], int display[10][2],int count) { //Team Score Input printf("Your team score: "); scanf("%d", &result[count][0]); //Opponent Score Input printf("Other team score: "); scanf("%d", &result[count][1]);

}

//Provides Current Record for Team void current_records(int result[10][2],int count) { int wins = 0, loss = 0, ties = 0; printf(" # Wins\t#Losses\t#Ties"); for (int i = 0; i result[i][1]) printf("%d", wins++); else if (result[i][0]

//Display Team Wins void display_win(int result[10][2], int count) { printf(" Your Score\tOpponent Score "); for (int i = 0; i result[i][1]) { printf(" %d\t\t%d", result[i][0], result[i][1]); } } }

//Display Low to High Opponent wins void display_op(int result[10][2], int display[10][2],int count) { for (int i = 0; i display[j][1]) { int temporary1 = display[i][1]; int temporary2 = display[i][0]; display[i][1] = display[j][1]; display[i][0] = display[j][0]; display[j][1] = temporary1; display[j][0] = temporary2;

} } }

for (int i = 0; i Program Specifications: ** MAIN MENU 1. A) Enter game results 2. B) Current Record (# of wins and # of losses and # of ties) 3. C) Display ALL results from all games WON 4. D) Display ALL results ordered by opponent score from low to high. 5. 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. Submission Requirements: Requirements will be same as the first assignment which will be the same for all future assignments. YOU CANNOT Use global variables, in this or any program ever. Use goto statement(s), in this or any program ever. Email your work to Tim, in this or any program ever

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!