part of code I really can't figure out

I assume its the calc(). thats where the error is coming up.

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
#include <iostream>

using namespace std;

int calc(int x, int y, int z, int a, short amount_touchdown, short touchdown, short amount_field_goal, short field_goal, short amount_extra_point, short extra_point, short amount_safety, short safety)
{
    return((amount_touchdown*touchdown=x) (amount_field_goal*field_goal=y) (amount_extra_point*extra_point=z)(amount_safety*safety=a)x+y+z+a);
}

int main()
{
    int x;
    int y;
    int z;
    int a;
    short touchdown=6;
    short amount_touchdown;
    short field_goal=3;
    short amount_field_goal;
    short extra_point=1;
    short amount_extra_point;
    short safety=2;
    short amount_safety;
    cout << "enter amount of touchdowns \n" << endl;
    cin >> amount_touchdown;
    cout << "enter amount of field_goals \n" << endl;
    cin >> amount_field_goal;
    cout << "enter amount of extra points \n" << endl;
    cin >> amount_extra_point;
    cout << "enter amount of safety" << endl;
    cin >> amount_safety;
    cout << calc(touchdown, field_goal, extra_point, safety, amount_extra_point, amount_field_goal, amount_safety, amount_touchdown, x, y, z, a) << endl;
    return 0;
}
Try this:

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
#include <iostream>

using namespace std;

int calc(int x, int y, int z, int a, short amount_touchdown, short touchdown, short amount_field_goal, short field_goal, short amount_extra_point, short extra_point, short amount_safety, short safety)
{
    return((amount_touchdown*touchdown) + (amount_field_goal*field_goal) + (amount_extra_point*extra_point) + (amount_safety*safety));
}

int main()
{
    int x;
    int y;
    int z;
    int a;
    short touchdown=6;
    short amount_touchdown;
    short field_goal=3;
    short amount_field_goal;
    short extra_point=1;
    short amount_extra_point;
    short safety=2;
    short amount_safety;
    cout << "enter amount of touchdowns \n" << endl;
    cin >> amount_touchdown;
    cout << "enter amount of field_goals \n" << endl;
    cin >> amount_field_goal;
    cout << "enter amount of extra points \n" << endl;
    cin >> amount_extra_point;
    cout << "enter amount of safety" << endl;
    cin >> amount_safety;
    cout << calc(touchdown, field_goal, extra_point, safety, amount_extra_point, amount_field_goal, amount_safety, amount_touchdown, x, y, z, a) << endl;
    return 0;
}


Is that what you wanted?
I believe your arguments in the call to calc function need to align with how you declared it.

calc(x, y, z, a, amount_touchdown, touchdown, amount_field_goal, field_goal, amount_extra_point, extra_point, amount_safety, safety

And your equations need to be switched to this format.


x = amount_touchdown*touchdown

that will get you to error C2064 which is an issue with your function I don't know about.
Maybe I'm a bit off here, but instead of correcting the code for the OP, why not explain what could be wrong which was the use of assignment which was backwards as well as improper use of the return statement.

As for your revised version, why not remove the variables that you don't use (a, x, y, z)? Now you're passing variables to a function that don't get used. Now let us say that the OP still wants to have the extra variables around to hold the values of the muliplications, why not also suggest that they still needn't be parameters. Just declare them inside the function so that you don't have those extra four lying around in the main function for no reason what so ever.

*Hint:* They are never even defined in the main function. When I compile:
Warning W8013 file.cpp 36: Possible use of 'x' before definition in function main()
Warning W8013 file.cpp 36: Possible use of 'y' before definition in function main()
Warning W8013 file.cpp 36: Possible use of 'z' before definition in function main()
Warning W8013 file.cpp 36: Possible use of 'a' before definition in function main()


The parameters are out of oder as well, you'll be calling touchdown as x and so on down the line.

Using short while it's getting converted to int is another thing, not as much of an issue, but it's another thing nonetheless.

As for the OP, don't just post your code and ask for people to correct it, it will never help you just to get someone else to do your work for you. Check this article out please:

http://www.cplusplus.com/forum/articles/1295/
Last edited on
The issue with the reversing of the equations might have something to do with pointers. I don't really feel like looking it up, but I get something about an Lvalue which has something to do with an address which is what pointers usually do, point to an address, but here, one isn't porvided.
x, y, z, and a need to be intialized to zero and this should be line 32.

cout << calc(x, y, z, a, amount_touchdown, touchdown, amount_field_goal, field_goal, amount_extra_point, extra_point, amount_safety, safety) << endl;
working code, thanks guys, helped a lot
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
#include <iostream>

using namespace std;

int calc(int touchdown, int field_goal, int extra_point, int safety, int amount_extra_point, int amount_field_goal, int amount_safety, int amount_touchdown)
{
    int x, y, z, a, b;
    x=(amount_touchdown*touchdown);
    y=(amount_field_goal*field_goal);
    z=(amount_extra_point*extra_point);
    a=(amount_safety*safety);
    b=x+y+z+a;
    return(b);
};

int main()
{
    int amount_touchdown, amount_field_goal, amount_extra_point, amount_safety;
    int touchdown=6;
    int field_goal=3;
    int extra_point=1;
    int safety=2;
    cout << "enter amount of touchdowns \n" << endl;
    cin >> amount_touchdown;
    cout << "enter amount of field_goals \n" << endl;
    cin >> amount_field_goal;
    cout << "enter amount of extra points \n" << endl;
    cin >> amount_extra_point;
    cout << "enter amount of safety \n" << endl;
    cin >> amount_safety;
    cout << calc(touchdown, field_goal, extra_point, safety, amount_extra_point, amount_field_goal, amount_safety, amount_touchdown) << endl;
    return 0;
};
and use creekist's return formula. I got it to compile without erros and it worked.
x, y, z, and a need to be intialized to zero and this should be line 32.

cout << calc(x, y, z, a, amount_touchdown, touchdown, amount_field_goal, field_goal, amount_extra_point, extra_point, amount_safety, safety) << endl;


No, that should not be line 32. The x, y, z, a variables were never used in the main function. So passing them into the calc function would be pointless.
Topic archived. No new replies allowed.