![]() |
|
#1
|
|||
|
|||
Need help with if else statements and functionsI am very new to C++. I need someone to look at my code and tell me if I am anywhere close to getting this assignment right and if not, point me the right direction. Thanks!
Here is the assignment: Your program shall read three integer test scores (between 0 and 100) from the keyboard. The program shall call a function (computeGrade) that calculates and returns a student’s grade based on the following requirements: 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%, examine the third score. If the third score is more than 90%, the grade is ‘A’, otherwise the grade is ‘B’. c. If the average score is 50% or more and less than 70%, examine the average of the second and third scores. If the average of the two is greater than 70%, the grade is ‘C’, otherwise, it is ‘D’. d. If the average score is less than 50% then the grade is ‘F’. The program’s main shall contain only call statements. At least three subfunctions (with the following names) are required: 1. readScore – Reads three test scores 2. determineGrade – Determine the student’s grade 3. printResults - Outputs the results to the computer’s monitor (screen) 5. Your program shall display the following text with answers in this format (Bold numbers are typical responses.): Student’s Test Scores: 75, 80, 95 Here's what I've written so far CPP / C++ / C Code:
Please help me! |
|
#2
|
||||
|
||||
Re: Need help with if else statements and functionsYikes. There's quite a bit wrong with this program:
1. There's no return statement or ending bracket for main. 2. finalNumericGrade and finalLetterGrade are never declared. letterGrade is never initialized or used. 3. Semicolons, semicolons, semicolons. Each declaration (int num1, etc.) needs to have a semicolon after it. 4. Your formatting is a mess. What's with the opening parentheses for the readScore return statement? Why is there a comma, then a semicolon at the end of that line? Why are you trying to return more than one value, especially from a void function? Is letterGrade a function? A variable declaration? 5. When you're initializing average, you need an equals sign. It should be "int average = ((num1 + num2 + num3) / 3);" 6. Is printResults supposed to be a function? Why do you have the prototype inside another function? 7. Your if statements look good in general, but they could be improved. In your elseif statements, you don't need to check that finalNumericGrade is < 90, 70, etc. In order for the program to get to that statement, (finalNumericGrade >= 90) must be false. In other words, checking if finalNumericGrade is less than 90 afterwords is redundant. Anyway, your functions are very unclear. It's hard to tell where one begins or ends, and what it's supposed to accomplish. Why don't you tell us the functions you plan to use, what they take as arguments, and what they're supposed to do. That will help us point you in the right direction. __________________
Gamer_2k4 |
|
#3
|
|||
|
|||
Re: Need help with if else statements and functionsThe functions are
readscore - which should get three integer test scores from the keyboard. CPP / C++ / C Code:
determineGrade - should calculate and return the students grade. CPP / C++ / C Code:
printResults - which should output to the monitor CPP / C++ / C Code:
|
|
#4
|
|||
|
|||
Re: Need help with if else statements and functionsI am also getting an error message "expected primary - expression before "else". I am not sure what that means.
|
|
#5
|
|||
|
|||
Re: Need help with if else statements and functionsQuote:
Kind of hard to spot, and the message isn't particularly enlightening (unless, like me, you have seen it about a million times) but: CPP / C++ / C Code:
The semicolon really screws things up here. (I think you could simplify things at least a little: When you get to the final "else if", is there any other possibility? I mean is it possible that the grade is not less than 50 at this point? If so, then you need some other assignment. If not, then why not eliminate the last if? (In other words change it to CPP / C++ / C Code:
Or something like that. Regards, Dave |
Recent GIDBlog
Python ebook by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Programs failing to execute...? | netnut | C++ Forum | 5 | 12-Jan-2006 10:39 |
| First prog, using functions that pass values... | boousaf | C Programming Language | 2 | 27-Sep-2005 16:10 |
| Pointers to Functions (was Saving some if statements) | TekiFreek | C++ Forum | 17 | 17-Jun-2004 11:25 |
| Understanding functions | tommy69 | C Programming Language | 15 | 15-Mar-2004 17:59 |
| JavaScript Tutorial Part 1 | pcxgamer | Web Design Forum | 2 | 01-Dec-2003 09:16 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The