![]() |
|
#1
|
|||
|
|||
Implementing a function into into my program?Hi, I've wrote my grade averaging program. But, my teacher is asking us to use functions and have the function return the average instead of the cout. This is what I have so far:
CPP / C++ / C Code:
Functions is new to me, as well as C++. |
|||
|
#2
|
|||
|
|||
Re: Implementing a function into into my program? Help!Quote:
CPP / C++ / C Code:
|
|
#3
|
|||
|
|||
Re: Implementing a function into into my program?I guess what i'm saying is. I'm trying to implement all of my "math" into the function, and then call it in my main function. I've correctly called functions, but, I don't understand this one. I don't know what to call since I'm averaging all the grades and outputting the average.
|
|
#4
|
|||
|
|||
Re: Implementing a function into into my program?This is what I have. But, I have a continuous loop, it isn't stopping..
CPP / C++ / C Code:
|
|
#5
|
|||
|
|||
Re: Implementing a function into into my program?CPP / C++ / C Code:
|
|
#6
|
|||
|
|||
Re: Implementing a function into into my program?1. Why should gradeCounter ever become more than maxgrades? You never change the value.
2. I don't think your instructor is being clear about your requirements for the function. If you never call cout/cin in the function gradeAvg, you will only average one value unless you: a) do fun math by making an average, then undoing the average and recalculating with another value. b) Pass a bunch of numbers into gradeAvg function, which means you have to know how to use std::list or std::vector, which seems a bit above the scope of this program. Either we or you need more details about your assignment to help you out. |
|
#7
|
|||
|
|||
Re: Implementing a function into into my program?Quote:
1. That's my loop control variable. 2. I totally agree on the instructors assignment. She hasn't be clear since day one! a) ?? Don't really understand. b) We haven't learned that yet.. Instructions as I see it: " Modify your get average program so that it returns the function rather than cout." |
|
#8
|
|||
|
|||
Re: Implementing a function into into my program?Did you fix the loop yet? You need to have that working correctly first.
CPP / C++ / C Code:
Quote:
Do you need to store the grades which the users inputs? If so you'll need to assign them to an array or something as they are entered within the loop. Regardless, you wouldn't call the average() function until you have: - the total of all the values - total number of input values So take the function call out of the loop, and instead add up the values as they are input within the loop , and then call a slightly different function than you presently have (which is close) CPP / C++ / C Code:
Last edited by Howard_L : 11-Oct-2008 at 20:35.
|
|
#9
|
|||
|
|||
Re: Implementing a function into into my program?Quote:
CPP / C++ / C Code:
|
Recent GIDBlog
Toyota - 2009 May Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| run script command on ns2.26 | newbie06 | Computer Software Forum - Linux | 65 | 19-Aug-2009 08:50 |
| Equation solver | RazoR | C Programming Language | 3 | 18-May-2008 10:24 |
| Airport Log program using 3D linked List : problem reading from file | batrsau | C Programming Language | 11 | 29-Feb-2008 08:44 |
| Need Help with input files. | Efferus | C++ Forum | 2 | 24-Nov-2007 17:19 |
| [Include] Doubly-linked List | dsmith | C Programming Language | 6 | 14-Apr-2006 14:12 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The