Write a Program That Asks the User to Enter Five Test Scores

Program:

#include <stdio.h>

int calcAverage(int a[]);
void determineGrade(int a);

int main()
{
int a[5],average;
printf("Enter 5 Test Scores:");
for(int i = 0; i<5;i++)
{
scanf("%d",&a[i]);
}

printf("\nGrades:\n");
for(int i = 0; i<5;i++)
{
determineGrade(a[i]);
}

average = calcAverage(a);
printf("\n\nAverage: %d",average);

   return 0;

}

//Function to calculate Average

int calcAverage(int a[])
{
int avg,sum=0;
for(int i=0;i<5;i++)
{
sum = sum+a[i];
}
avg = sum / 5;
return avg;
}

//Function to determine Grade

void determineGrade(int a)
{
if(a>=90 && a<=100)
{
printf("%d - A\n",a);
}
if(a<=89 && a>=80)
{
printf("%d - B\n",a);
}
if(a<=79 && a>=70)
{
printf("%d - C\n",a);
}
if(a<=69 && a>=60)
{
printf("%d - D\n",a);
}
if(a<60)
{
printf("%d - FAIL\n",a);
}
}

#include <stdio.h> int calcAverage(int a[]); void determineGrade(int a); int main() { int a[5], average; printf(Enter 5 Test int calcAverage (int a[]) { int avg, sum=0; for(int i=0;i<5;i++) { sum = sum+a[i]; } avg = sum / 5; return avg; } void determ Enter 5 Test Scores: 95 85 75 65 55 Grades: 95 - A 85 - B 75 - C 65 - D 55 - FAIL Average: 75 ... Program finished with exit

1. IPO CHARTS:

a> CalcAverage Function

INPUT

PROCESS

OUTPUT

Test Scores

Ø Sum the test scores

Ø Divide Sum of test scores with 5

Ø Output Average

Average

b> determineGrade Function:

INPUT

PROCESS

OUTPUT

Test Scores

Ø Score >= 90 AND score <= 100

Display "A"

Ø score <= 89 AND score >= 80

Display "B"

Ø score<=79 AND score >= 70

Display "C"

Ø score <= 69 AND score >= 60

Display "D"

Ø score < 60

Display "FAIL"

Grades

c> getValidScore Function

INPUT

PROCESS

OUTPUT

Test Scores

Ø Score >= 0 AND score <= 100

Return Score

Score

d> isValidScore Function

INPUT

PROCESS

OUTPUT

Test Scores

Ø Score >= 0 AND score <= 100

Display "ValidScore"

Ø Score < 0 OR score > 100

Display "IN ValidScore"

Valid/Invalid Score

2)

Pseudocodes:

a> CalcAverage Function

Initialize sum to 0 // Initialising a variable to calculate sum of numbers
FOR i IN 1 TO 5
DO sum = sum+a[i] // Calculating sum of all numbers in the array
ENDFOR;
avg = sum / 5 // Calculating Average of all the numbers i.e; Avg = (Sum Of Num)/Total num
Print avg // Prints The Average

b> determineGrade Function:

IF marks>=90 AND marks<=100 // Conditonal Statement to check whether the marks >=90 & mark<=100
Print "A" //then it prints Grade 'A'
ENDIF
IF marks<=89 AND marks>=80 //Conditonal Statement to check whether the marks <=89 & mark>=80
Print "B" //then it prints Grade 'B'
ENDIF
IF marks<=79 AND marks>=70   //Conditonal Statement to check whether the marks <=79 & mark>=70
Print "C"   //then it prints Grade 'C'
ENDIF
IF marks<=69 AND marks>=60 //Conditonal Statement to check whether the marks <=69 & mark>=60
Print "D"   //then it prints Grade 'D'
ENDIF
IF marks<60 //Conditonal Statement to check whether the marks < 60
Print "Fail"   //then it prints 'FAIL'
ENDIF

c> isValidScore Function
IF marks>=0 AND marks<=100 // Valid score is between marks 0 and 100
RETURN True // If user enters the score between the range 0 and 100 then it returns TRUE
ELSE
RETURN False // If user doesn't enters the score between the range 0 and 100 then it returns FALSE
ENDIF

c> getValidScore Function

IF marks>=0 AND marks<=100 // Valid score is between marks 0 and 100
return marks    // If user enters the score between the range 0 and 100 then it returns marks
ELSE
return -1 // If user doesn't enters the score between the range 0 and 100 then it returns -1
ENDIF

#include <stdio.h> int calcAverage(int a[]); void determineGrade(int a); int main() { int a[5], average; printf("Enter 5 Test Scores:"); for(int i = 0; i<5;i++) { scanf("%d",&a[i]); } printf("\nGrades: \n"); for(int i = 0; i<5;i++) { determineGrade (a[i]); } average = calcAverage(a); printf("\n\nAverage: %d", average); return 0; }

int calcAverage (int a[]) { int avg, sum=0; for(int i=0;i<5;i++) { sum = sum+a[i]; } avg = sum / 5; return avg; } void determineGrade(int a) { if(a>=90 && a< =100) { printf("%d - A\n", a); } if(a<=89 && a >=80) { printf("%d - B\n", a); } if(a<=79 && a>=70) { printf("%d C\n", a); } if(a<=69 && a >=60) { printf("%d D\n", a); } if(a<60) { printf("%d - FAIL\n", a); } }

Enter 5 Test Scores: 95 85 75 65 55 Grades: 95 - A 85 - B 75 - C 65 - D 55 - FAIL Average: 75 ... Program finished with exit code 0 Press ENTER to exit console.

Write a Program That Asks the User to Enter Five Test Scores

Source: https://itprospt.com/qa/291222/write-a-program-that-asks-the-user-to-enter-five

0 Response to "Write a Program That Asks the User to Enter Five Test Scores"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel