coint counter w/ function not working

What am I doing wrong here, clearly it is not calling the amount of coins to the function because the total is giving me a weird output everytime.
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
#include <iostream>
#include <cmath>
#include <string.h>
#include <math.h>

using namespace std;

double totalValue(int numberofpennies, int numberofnickels, int numberofdimes, int numberofquarters);


	int main()
	{
		
		int numberofpennies;
		int numberofnickels;
		int numberofdimes;
		int numberofquarters;
		double total;
		string continueProgram = "Y";

		cout << "Please enter the number of pennies: " << endl;
		cin >> numberofpennies;

		cout << "Please enter the number of nickles: " << endl;
		cin >> numberofnickels;

		cout << "Please enter the number of dimes: " << endl;
		cin >> numberofdimes;

		cout << "Please enter the number of quarters: " << endl;
		cin >> numberofquarters;

		cout.setf(ios::fixed);
		cout.setf(ios::showpoint);
		cout.precision(2);
		cout << "The total amount of money is: " << endl;
		cout << "$ " << totalValue << endl;

		system("pause");
		return 0;

	}

	double totalValue(int numberofpennies, int numberofnickels, int numberofdimes, int numberofquarters)
	{
		
	double total;
	total = (numberofpennies * 0.01) + (numberofnickels * 0.05) + (numberofdimes * 0.10) + (numberofquarters * 0.25);

	return total;

	}

Last edited on
Hello PistolPete10,

Please always use code tages (the <> icon on the right of the text box) it makes it a lot easier for people to read and understand your code.

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
#include <iostream>
#include <cmath>
#include <string.h>
#include <math.h>

using namespace std;

double totalValue(int, int, int, int);


int main()
{
	int numberofpennies;
	int numberofnickels;
	int numberofdimes;
	int numberofquarters;
	double total;
	string continueProgram = "Y";

	cout << "Please enter the number of pennies: ";
	cin >> numberofpennies;
	
	cout << "Please enter the number of nickles: ";
	cin >> numberofnickels;

	cout << "Please enter the number of dimes: ";
	cin >> numberofdimes;
	
	cout << "Please enter the number of quarters: ";
	cin >> numberofquarters;
	
	cout << "The total amount of money is: ";
	cout << totalValue(numberofpennies, numberofnickels, numberofdimes, numberofquarters) << "\n";
	
	system("pause");
	
	
	return 0;
}

double totalValue(int numberofpennies, int numberofnickels, int numberofdimes, int numberofquarters)
{
	float total = 0;
	total = (numberofpennies * 0.01) + (numberofnickels * 0.05) + (numberofdimes * 0.10) + (numberofquarters * 0.25);
	
	return total;
}


I'm surprised your code even worked, since you were calling function totalValue(int, int, int, int) without it's parentheses and arguments.

You're not using string continueProgram = "Y";, what is your intention with that string? It looks like a loop flag.

Also, in your totalValue funciton, there is no need for having cout << "You have this amount of money :" << total << endl; since you return the total value to main and display it from there.

Hope this helps,

Regards,

Hugo.

(the <> icon on the right of the text box)

I believe it's actually underneath the text box when you originate a post.

And it can of course be typed like this:

[code]
put your program in between the tags
[/code]
Last edited on
@dutch
Oh.. My bad, I need to stop saying this.. noted..
I plan on using the continueProgram to loop the progam once i start getting the program to display the correct total. I do not get what I am doing wrong here.
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
#include <iostream>
#include <cmath>
#include <string.h>
#include <math.h>

using namespace std;

double totalValue(int numberofpennies, int numberofnickels, int numberofdimes, int numberofquarters);


	int main()
	{
		
		int numberofpennies;
		int numberofnickels;
		int numberofdimes;
		int numberofquarters;
		double total;
		string continueProgram = "Y";

		cout << "Please enter the number of pennies: " << endl;
		cin >> numberofpennies;

		cout << "Please enter the number of nickles: " << endl;
		cin >> numberofnickels;

		cout << "Please enter the number of dimes: " << endl;
		cin >> numberofdimes;

		cout << "Please enter the number of quarters: " << endl;
		cin >> numberofquarters;

		cout << "The total amount of money is: " << endl;
		cout << totalValue << endl;

		system("pause");
		return 0;

	}

	double totalValue(int numberofpennies, int numberofnickels, int numberofdimes, int numberofquarters)
	{
		
	float total = 0.0;
	total = (numberofpennies * 0.01) + (numberofnickels * 0.05) + (numberofdimes * 0.10) + (numberofquarters * 0.25);

	return total;

	}
As I told you above, you're doing here the same mistake: line 34 cout << totalValue << endl; you're calling the function totalValue without its parameters and parentheses, that's why it doesn't work.

Read my previous answer and the code I posted :)
Last edited on
H00G0 thank you so much, knew it was something so easy I was missing. Your the best!
You're welcome, glad to have helped!
cmath and math.h are the same thing, except math.h is for C programs. Don't include it twice, just stick to cmath.

its not actually calling totalvalue, its printing its address as if a function pointer. Its one of those things that compiles and runs fine, but is totally not what you wanted.
Last edited on
Registered users can post here. Sign in or register to post.