new to c++ and functions assistance please?

Well i'm writing this for my c++ class in school and I just would like help with this and please don't make me feel stupid.

Well here's the code, could someone tell me what I did wrong?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
using namespace std;

void heading();
void GradeName(string name1, int grade1, int grade2, int grade3, int grade4, int grade5);
void average();
void output();

int main(string name1, int grade1, int grade2, int grade3, int grade4, int grade5) {

GradeName(name1, grade1, grade2, grade3, grade4, grade5);
heading();

return 1;

}

void heading() {

cout << "Welcome to the Grade Averager! \n";
cout << "I am Jimmy and I will be your hostess! \n";
cout << "We are gonna have so much fun! \n\n";


}

void GradeName(string name1, int G1, int G2, int G3, int G4, int G5)
{

cout << "Please enter your name! -  " << "\n";
cin >> name1;
cout << "Thank you now could you please enter your grades when prompted? F**KING JUST DO IT!" << "\n\n";
cout << "What is you Math grade?" << "\n";
cin >> G1;
cout << "Im guessing your english grade is terrible so I will just put it in for you which is a 69..HAHAHAHA!! get it? LOL!!" << "\n";
G2 = 69;
cout << "Science grade plox?" << "\n";
cin >> G3;
cout << "What is you language grade...i.e how much of a failure are you at it?!?!?!" << "\n";
cin >> G4;
cout << "What is you band grade? Well it must be a 100 because...well I really don't know...LOL!!!!" << "\n";
cin >> G5;

}


I get warnings but no "errors".
Last edited on
Well, to begin with, you're calling GradeName before your heading. That doesn't seem right.

You're also passing the parameters to GradeName by value, which means you don't get the modified versions back in main(). When you pass by value, the called routine makes a local copy of the variables, and they're destroyed when the called routine exits. You need to pass by reference instead.

Finally...there's no averaging algorithm in place. You didn't expect the program to do it for you, did you?
main() can't take any arguments you want it to. It's () or (int, char**). You'll have to declare those variables as locals.
Another thing is that you should pass arguments to GradeName by reference. Right now, the changes you make to them don't affect anything outside the function.
If there's something I missed, post the errors or warnings.
too slow ;(
Last edited on
Oh yeah, good catch on the main parameters, hamsterman. I didn't even notice that.
Thanks for all the help but could someone just give me a reference to what they mean? Like take some of my code and show me how it would be done? I get what you saying I'm just really at a loss for how to implement it. What i'm really trying to ask is how do you pass by reference and not not by value.
Last edited on
Here's a good, quick rundown on passing by reference:

http://www.learncpp.com/cpp-tutorial/73-passing-arguments-by-reference/
Thanks everyone who helped. Not solved yet but I hope I will figure it out soon!
you are not using average() and output() function .so y declare them
Because i'm not finished yet? My teacher wanted it all written in functions and I just needed help with one to understand the rest.
Topic archived. No new replies allowed.