Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include<stdio.h> #include<conio.h> void main() { double count,rating,highiestra

ID: 3723316 • Letter: #

Question

#include<stdio.h>
#include<conio.h>

void main()

{ double count,rating,highiestrating=0,lowestrating=0, totalrating=0;

float averagerating=0.0;

clrscr();

//Accept 5 valid entries

for (count=1;count<=5;count++)

{

rating=AcceptData();

if(rating>0) //calculateonly when entry is valid

{

totalrating=totalrating+rating;

highestrating= FindHighest(rating,highestrating);

lowestrating=FindLowest(rating,lowestrating);

averagerating=FindAverage(count,totalrating);

} //end if

else

{

count--; // re enter when rating is not valid

}

} //end for

printf("Highest Rating: %d", highiestrating);

printf("Lowest Rating: %d", lowestrating);

printf("Average Rating: %.2f", averagerating); //print the avaegae in two decimal places

} //end main

//Calculate the average in decimal places

float FindAverage(int num,int total)

{

return total/num ;

}

//Find the lowest rating

int FindLowest(int num,int lowest)

{

if (num>lowest)

return lowest;

else

return num;  

}

//Find the Highest Rating

int FindHighest(int num,int highest)

{

if (num>highest)

return num;

else

return highest;  

}

//Accept the input

int AcceptData()

{

int intRating=0;

printf("Enter a rating in 1-10 scale ");

scanf("%d",&intRating);

if(!CheckRating(intRating))

return intRating;

else

{printf ("Please enter a valid number between 1 to 10");

return 0;

}

}

//Check the rating if entered whole number and between 1 to 10

int CheckRating(int num)

{

if(num%2==0 && num>0 && num<=10)

return num;

else

return 0;
}

Explanation / Answer

Removed all compile time errors.

========================================================================

#include <stdio.h>
#include <conio.h>
//Calculate the average in decimal places

float FindAverage(double num, double total)

{

return total / num;
}

//Find the lowest rating

int FindLowest(int num, int lowest)

{

if (num > lowest)

return lowest;

else

return num;
}

//Find the Highest Rating

int FindHighest(int num, int highest)

{

if (num > highest)

return num;

else

return highest;
}

//Accept the input

int AcceptData()

{

int intRating = 0;

printf("Enter a rating in 1-10 scale ");

scanf("%d", &intRating);

if (!CheckRating(intRating))

return intRating;

else

{
printf("Please enter a valid number between 1 to 10");

return 0;
}
}

//Check the rating if entered whole number and between 1 to 10

int CheckRating(int num)

{

if (num % 2 == 0 && num > 0 && num <= 10)

return num;

else

return 0;
}

void main()

{
double count, rating, highiestrating = 0, lowestrating = 0, totalrating = 0, highestrating;

float averagerating = 0.0;

//Accept 5 valid entries

for (count = 1; count <= 5; count++)

{

rating = AcceptData();

if (rating > 0) //calculateonly when entry is valid

{

totalrating = totalrating + rating;

highestrating = FindHighest(rating, highestrating);

lowestrating = FindLowest(rating, lowestrating);

averagerating = FindAverage(count, totalrating);

} //end if

else

{

count--; // re enter when rating is not valid
}

} //end for

printf("Highest Rating: %d", highiestrating);

printf("Lowest Rating: %d", lowestrating);

printf("Average Rating: %.2f", averagerating); //print the avaegae in two decimal places

} //end main