struct problems

I'm supposed to be writting a program to calculate change using structs and functions. I cannot get this down. when I compile it i get this as the answer:
-858993460-858993460-858993460-85899346045
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
45
46
47
48
49
50
51
52
53
 #include <iostream>
#include <string>
using namespace std;

struct change
{
	int quarters, dimes, nickels, pennies;
	int cents;
};

change ComputeChange(int cents){
	change c;
	c.quarters = cents / 25;
	c.cents = cents % 25;
	c.dimes = cents / 10;
	c.cents = cents % 10;
	c.nickels = cents / 5;
	c.cents = cents % 05;
	c.pennies = cents / 1;
	c.cents = cents % 01;

	return c;

}



void PrintChange(change c){

	cout << c.quarters;
	cout << c.dimes;
	cout << c.nickels;
	cout << c.pennies;
	cout << c.cents;

	return;
}

int main(int argc, const char* argv[]){
	change FirstGiven;
	change SecondGiven;

	FirstGiven.cents = 45;
	SecondGiven.cents = 55;

	ComputeChange(FirstGiven.cents);
	PrintChange(FirstGiven);

	cin.get();
	return 0;
} 

You aren't doing anything with what you are returning from ComputeChange. On line 11 you say you are returning a change object but then in main you are ignoring it.
ok so in the main would i put something like:

int main(int argc, const char* argv[]){
change c;

ComputeChange(c.cents);
PrintChange(c);

cin.get();
return0;

}

//because after this i still get the same numbers when i compile. I apologize for my ignorance.
1
2
3
4
5
6
7
int main()
{
    int cents = 0;
    std::cin >> cents;
    change c = ComputeChange(cents); //notice this line here
    PrintChange(c);
}
In your first example ComputeChange returns c but you never pass it to PrintChange.

 
	PrintChange(ComputeChange(FirstGiven.cents));
thanks alot that really helped. I also had the calculation wrong for the change but i figured that out.
Topic archived. No new replies allowed.