Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void enableFlushAfterPrintf()
- {
- setvbuf(stdout, 0, _IONBF, 0);
- setvbuf(stdin, 0, _IONBF, 0);
- }
- float getAvg(int list, float *scorearray);
- float getUser( float score);
- float calculatepercent(float score, float max);
- char getGrade(float pt, char grade);
- void printline(char line,int count);
- int main()
- {
- enableFlushAfterPrintf();
- int option;
- int score;
- float scorearray[100]={0};
- int list;
- float pct;
- char grade;
- bool name_ent=false;
- bool score_ent=false;
- int sum;
- do
- {
- printline('A', 10);
- printf("1. Enter name\n");
- printf("2. Enter exam scores:\n");
- printf("3. Display average exam scores\n");
- printf("4. Display summary\n");
- printf("5. Quit\n");
- char name[32]={0};
- scanf("%i", &option);
- if (1 == option)
- {
- name_ent = true;
- printf("Enter your name: ");
- scanf("%s", name);
- }
- else if (2 == option)
- {
- score_ent=true;
- printf("How many scores are there");
- scanf("%i", &list);
- for (int i=0; i<list; i++)
- {
- scorearray[i]=getUser(score);
- }
- }
- else if (3==option)
- {
- if (score_ent)
- {
- printf("Your score is : %2.2f\n", getAvg(list, scorearray));
- }
- else
- {
- printf("Please use the menu to enter your score first.\n");
- }
- }
- else if (4==option)
- {
- if (score_ent && name_ent)
- {
- printf("Hello %s, according to your test scores of, ", name);
- for (int i=0; i<list; i++)
- {
- printf("%d", scorearray[i]);
- }
- printf("the average score is %2.2f with a letter grade of %c.\n", getAvg(list, scorearray), getGrade(pct,grade));
- }
- else
- {
- printf("Please use the menu to enter your name and score first.\n");
- }
- }
- }while (option !=5);
- }
- float getUser( float score)
- {
- printf("What was the score of this exam?");
- scanf("%f", &score);
- return score;
- }
- float getAvg(int list, float *scorearray)
- {
- float ave=0;
- for (int i=0; i<list; i++)
- {
- ave+=scorearray[i]/list;
- }
- return ave;
- }
- float calculatepercent(float score, float max)
- {
- float pt = score / max;
- return pt;
- }
- char getGrade(float pt, char grade)
- {
- if (pt >= 90)
- {
- grade = 'A';
- }
- else if (pt >= 80)
- {
- grade = 'B';
- }
- else if (pt >= 70)
- {
- grade = 'C';
- }
- else if (pt >= 60)
- {
- grade = 'D';
- }
- else
- {
- grade = 'F';
- }
- return grade;
- }
- void printline(char line, int count)
- {
- for (int i=0; i<count; i++)
- {
- printf("%c", line);
- }
- printf("\n");
- }
Add Comment
Please, Sign In to add comment