Click here to Skip to main content
15,891,633 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionC programming Determine Students grade Pin
hoangtrungl22-Jun-17 22:47
hoangtrungl22-Jun-17 22:47 
AnswerRe: C programming Determine Students grade Pin
OriginalGriff22-Jun-17 22:54
mveOriginalGriff22-Jun-17 22:54 
AnswerRe: C programming Determine Students grade Pin
Jochen Arndt22-Jun-17 23:12
professionalJochen Arndt22-Jun-17 23:12 
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 to GetGrade() (which can free allocated memory) which returns the grade that is passed to the Print() function.
[/EDIT]

modified 23-Jun-17 5:49am.

QuestionRe: C programming Determine Students grade Pin
David Crow23-Jun-17 4:05
David Crow23-Jun-17 4:05 
AnswerRe: C programming Determine Students grade Pin
Bram van Kampen28-Jun-17 12:35
Bram van Kampen28-Jun-17 12:35 
QuestionHow to solve this compiler error. Pin
pankajkumar21-Jun-17 2:42
pankajkumar21-Jun-17 2:42 
NewsRe: How to solve this compiler error. Pin
Jochen Arndt21-Jun-17 3:23
professionalJochen Arndt21-Jun-17 3:23 
GeneralRe: How to solve this compiler error. Pin
pankajkumar23-Jun-17 2:19
pankajkumar23-Jun-17 2:19 
GeneralRe: How to solve this compiler error. Pin
Jochen Arndt23-Jun-17 2:41
professionalJochen Arndt23-Jun-17 2:41 
AnswerRe: How to solve this compiler error. Pin
Victor Nijegorodov21-Jun-17 8:39
Victor Nijegorodov21-Jun-17 8:39 
GeneralRe: How to solve this compiler error. Pin
pankajkumar23-Jun-17 2:26
pankajkumar23-Jun-17 2:26 
GeneralRe: How to solve this compiler error....changed IDE Pin
pankajkumar23-Jun-17 23:11
pankajkumar23-Jun-17 23:11 
QuestionMessage Closed Pin
21-Jun-17 0:00
东 楷21-Jun-17 0:00 
AnswerRe: How to use LM317T? Pin
Richard MacCutchan21-Jun-17 2:24
mveRichard MacCutchan21-Jun-17 2:24 
AnswerRe: How to use LM317T? Pin
leon de boer21-Jun-17 2:40
leon de boer21-Jun-17 2:40 
GeneralRe: How to use LM317T? Pin
Jochen Arndt21-Jun-17 3:04
professionalJochen Arndt21-Jun-17 3:04 
GeneralRe: How to use LM317T? Pin
leon de boer21-Jun-17 3:39
leon de boer21-Jun-17 3:39 
QuestionNeed Source Code for Decoding _Using algorithm Pin
Member 1326117519-Jun-17 23:29
Member 1326117519-Jun-17 23:29 
QuestionRe: Need Source Code for Decoding _Using algorithm Pin
Richard MacCutchan20-Jun-17 0:03
mveRichard MacCutchan20-Jun-17 0:03 
AnswerRe: Need Source Code for Decoding _Using algorithm Pin
Member 1326117520-Jun-17 1:46
Member 1326117520-Jun-17 1:46 
GeneralRe: Need Source Code for Decoding _Using algorithm Pin
Member 1326117520-Jun-17 1:47
Member 1326117520-Jun-17 1:47 
GeneralRe: Need Source Code for Decoding _Using algorithm Pin
leon de boer20-Jun-17 3:34
leon de boer20-Jun-17 3:34 
GeneralRe: Need Source Code for Decoding _Using algorithm Pin
Member 1326117520-Jun-17 22:32
Member 1326117520-Jun-17 22:32 
GeneralRe: Need Source Code for Decoding _Using algorithm Pin
leon de boer21-Jun-17 2:08
leon de boer21-Jun-17 2:08 
GeneralRe: Need Source Code for Decoding _Using algorithm Pin
Member 1326117521-Jun-17 2:16
Member 1326117521-Jun-17 2:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.