C programming Determine Students grade
-
Write a program that determines a student's grade. It reads three test scores(between 0 and 100) and calls a function that calculates and returns a student's grade based on the following rules: A. If the average score is 90% or more, the grade is A. B. If the average score is 70% or more and less than 90%, it checks the third score. If the third score is more than 90%, the grade is A; otherwise, the grade is B. and it continues... The program's main is to contain only call statements. At least three subfunctions are required: one to read scores, one to determine the grade, and one to print the results. This is what I have so far but it will not run for me. I am not allowed to use global declarations
-
Write a program that determines a student's grade. It reads three test scores(between 0 and 100) and calls a function that calculates and returns a student's grade based on the following rules: A. If the average score is 90% or more, the grade is A. B. If the average score is 70% or more and less than 90%, it checks the third score. If the third score is more than 90%, the grade is A; otherwise, the grade is B. and it continues... The program's main is to contain only call statements. At least three subfunctions are required: one to read scores, one to determine the grade, and one to print the results. This is what I have so far but it will not run for me. I am not allowed to use global declarations
You don't show what you have so far, so we can't really give you any explicit help. But ... if you can't use global declarations, then you need to use local variables and parameter passing. That means you write your functions to accept the data they are to work on, and return values to the caller. For example:
int sum (int* data, int count)
{
int i;
int total = 0;
for (i = 0; i < count; i++)
{
total += *data++;
}
return total;
}
...
int main()
{
int result;
int data[100];
int i;
for (i = 0; i < 5; i++)
{
data[i] = i + 1;
}
result = sum(data, 5);
printf("%u\n", result);
}Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
-
Write a program that determines a student's grade. It reads three test scores(between 0 and 100) and calls a function that calculates and returns a student's grade based on the following rules: A. If the average score is 90% or more, the grade is A. B. If the average score is 70% or more and less than 90%, it checks the third score. If the third score is more than 90%, the grade is A; otherwise, the grade is B. and it continues... The program's main is to contain only call statements. At least three subfunctions are required: one to read scores, one to determine the grade, and one to print the results. This is what I have so far but it will not run for me. I am not allowed to use global declarations
This requires to use variables to hold the scores and the grade. If you are not allowed to use global variables you must declare them in your
main()
function and pass them to the functions:int main()
{
int grade;
int score1, score2, score2;ReadScores(&score1, &score2, &score3); grade = GetGrade(score1, score2, score3); PrintGrade(grade); return 0;
}
hoangtrungl wrote:
The program's main is to contain only call statements.
I would read that in the sense of that it should not contain any operations but that variable declarations, assignment, and the mandatory return statement are allowed. [EDIT] After thinking about it a while I found a solution that does not use any variables in
main()
:int main()
{
PrintGrade(GetGrade(ReadScores()));
return 0;
}Then
ReadScores()
must return a structure containing the data (which may be optionally dynamically allocated) that is passed toGetGrade()
(which can free allocated memory) which returns the grade that is passed to thePrint()
function. [/EDIT] -
Write a program that determines a student's grade. It reads three test scores(between 0 and 100) and calls a function that calculates and returns a student's grade based on the following rules: A. If the average score is 90% or more, the grade is A. B. If the average score is 70% or more and less than 90%, it checks the third score. If the third score is more than 90%, the grade is A; otherwise, the grade is B. and it continues... The program's main is to contain only call statements. At least three subfunctions are required: one to read scores, one to determine the grade, and one to print the results. This is what I have so far but it will not run for me. I am not allowed to use global declarations
hoangtrungl wrote:
This is what I have so far...
:confused:
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
Write a program that determines a student's grade. It reads three test scores(between 0 and 100) and calls a function that calculates and returns a student's grade based on the following rules: A. If the average score is 90% or more, the grade is A. B. If the average score is 70% or more and less than 90%, it checks the third score. If the third score is more than 90%, the grade is A; otherwise, the grade is B. and it continues... The program's main is to contain only call statements. At least three subfunctions are required: one to read scores, one to determine the grade, and one to print the results. This is what I have so far but it will not run for me. I am not allowed to use global declarations
Hmm Ah, it is that time of the year again. This looks suspiciously like an examination project. There are various reasons why this forum does not do these. For one, most people on this forum have already passed their exams, while many others earned their feathers trough self study and hard graft. Furthermore we would not like to contribute to the creation of qualified software engineers who mis the basic concepts.(as you seem to do). You don't actually show what you have. (maybe you don't know how to, if so, follow the posting guidelines on this site.) Show me yours, and I'll show you Mine. :)
Bram van Kampen