Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdbool.h>
- #include <string.h>
- int main()
- {
- int loop =14;
- int NumberOfExams = 3;
- float max = 100.00;
- float score[NumberOfExams];
- float percentage = -1;
- char quit = 'a';
- char letter = 'F';
- float total = 0;
- float avg = 0;
- char name[20];
- //int i = 0;
- int safety = 0;
- int command = 0;
- while(loop == 14){
- printf("1. Enter name\n");
- printf("2. Enter Exams\n");
- printf("3. Display Average Exam Score\n");
- printf("4. Display Summary\n");
- printf("5. Quit\n");
- scanf("%d",&command);
- if (command == 1){
- printf("Please enter your first name: ");
- scanf("%s", &name);
- //scanf("%[^\n]s",&name);
- }
- if(command == 2){
- for(int i = 0; i<NumberOfExams ;i++){
- printf("What is your score: ");
- scanf("%f", &score[i]);
- if(score[i] > max) {
- printf("Error, score is invalid. Please reset the board\n");
- goto end;
- }
- }
- for(int i = 0; i<NumberOfExams ; i++){
- total = total + score[i];
- }
- avg = total/NumberOfExams;
- percentage = avg/max * 100.00;
- if(avg > max) {
- printf("Error, score is invalid. Please reset the board\n");
- goto end;
- }
- else if(percentage >= 90) {
- letter = 'A';
- }
- else if(percentage >= 80) {
- letter = 'B';
- }
- else if(percentage >= 70) {
- letter = 'C';
- }
- else if(percentage >= 60) {
- letter = 'D';
- }
- else{
- letter = 'F';
- }
- }
- if(command == 3){
- printf("Your average is %0.2f%%", avg);
- }
- if(command == 4){
- printf("Hello, %s, based on your exams of %0.2f%%, %0.2f%%, and %0.2f%%. Your average was %0.2f%% with a letter grade of %c.\n", name, score[0], score[1], score[2],avg ,letter);
- }
- if(command == 5){
- loop = 49;
- goto end;
- }
- safety++;
- if(safety>20){
- break;
- }
- }
- end: printf("Program finished, press any key to quit ... ");
- getchar();
- getchar();
- scanf("%c", &quit);
- printf("\nYou pressed %c to quit the program\n", quit);
- printf("Goodbye\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement