I'm bad at functions, keep getting errors

The user enters the amount of cents and the program is supposed to output it in quarters, dimes, and pennies. Then it prompts them to go again.

The errors are near the end in a comment

I usually have trouble defining the variables right so maybe that's it?
Thanks

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
54
#include <iostream>
#include <cmath>
using namespace std;

int inputAmountGiven(int& amountGiven);
int coinsUsed(int amountGiven, int& quartersUsed, int& dimesUsed);
void output(int amountGiven, int& quartersUsed, int& dimesUsed, int& penniesUsed, char input);


int main()
{
	char input = 'y';
	while (input == 'y')
	{
		int inputAmountGiven(int& amountGiven);
		cout << "Enter y to repeat, any other key to quit " << endl;
		cin >> input;
	}
}

int inputAmountGiven(int& amountGiven)
{

	cout << "Enter amount of cents from 1 to 99:  " << endl;
	cin >> amountGiven;
}
int quartersUsed = 0, dimesUsed = 0, penniesUsed = 0;
int coinsUsed(int amountGiven, int quartersUsed, int dimesUsed)
{

	if (amountGiven >= 25)
	{
		quartersUsed = amountGiven / 25;
	}
	else quartersUsed = 0;

	if (amountGiven - quartersUsed >= 10)
	{
		dimesUsed = (amountGiven % 25) / 10;
	}
	else dimesUsed = 0;
	if (amountGiven - quartersUsed - dimesUsed > 0) 
		{
			dimesUsed = amountGiven - (quartersUsed * 25) - (dimesUsed * 10);

		}

	void output(int amountGiven, int& quartersUsed, int& dimesUsed, int& penniesUsed, char input) 
	{ //expected a ';' and 'output': local function definitions are illegal

		cout << amountGiven << " is equal to " << quartersUsed << " quarters, " << dimesUsed << " dimes, and " << penniesUsed << " pennies. \nEnter y to go again or any other key to end. " << endl;
		cin >> input;
	}
}
See how every function starts at the very beginning of the line, except for the function output on line 48? That's something of a clue. The previous function, coinsused, has to finish before the next function starts.

local function definitions are illegal

You have written the code of function 'output' on lines 48-53. That is inside function 'coinsUsed' whose ending brace is on line 54. That is not legal.


PS. On line 15 you do have a function declaration. Not a function call.
thanks guys. I tried to fix what you said but I'm not very smart with this. I got it to run with no errors, but all it does is prompt "Enter y to repeat, any other key to quit" over and over. How do I get it to do the other stuff? thanks

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
54
55
56
57

#include <iostream>
#include <cmath>
using namespace std;

int inputAmountGiven(int& amountGiven);
int coinsUsed(int amountGiven, int& quartersUsed, int& dimesUsed, int& penniesUsed);
void output(int amountGiven, int& quartersUsed, int& dimesUsed, int& penniesUsed, char input);


int main()
{
	char input = 'y';
	while (input == 'y')
	{
		int inputAmountGiven(int& amountGiven);
		cout << "Enter y to repeat, any other key to quit " << endl;
		cin >> input;
	}
}

int inputAmountGiven(int& amountGiven)
{

	cout << "Enter amount of cents from 1 to 99:  " << endl;
	cin >> amountGiven;

	return 0;
}
int quartersUsed = 0, dimesUsed = 0, penniesUsed = 0;
int coinsUsed(int amountGiven, int quartersUsed, int dimesUsed, int penniesUsed)
{

	if (amountGiven >= 25)
	{
		quartersUsed = amountGiven / 25;
	}
	else quartersUsed = 0;

	if (amountGiven - quartersUsed >= 10)
	{
		dimesUsed = (amountGiven % 25) / 10;
	}
	else dimesUsed = 0;
	if (amountGiven - quartersUsed - dimesUsed > 0)
	{
		penniesUsed = amountGiven - (quartersUsed * 25) - (dimesUsed * 10);

	}
	return quartersUsed, dimesUsed, penniesUsed;
}
void output(int amountGiven, int& quartersUsed, int& dimesUsed, int& penniesUsed, char input)
{

	cout << amountGiven << " is equal to " << quartersUsed << " quarters, " << dimesUsed << " dimes, and " << penniesUsed << " pennies. \nEnter y to go again or any other key to end. " << endl;
	cin >> input;
}
What I wrote as PS about (now line 16)?

See
http://www.cplusplus.com/doc/tutorial/functions/
I tried to follow what it says but I get a red squiggly line under amountGiven. I feel really stupid & frustrated with myself because I've been working on this all day and can't figure out how to apply any examples to my own code.
1
2
3
4
5
6
7
	{
		input = inputAmountGiven(amountGiven);
		cout << "Enter y to repeat, any other key to quit " << endl;
		cin >> input;
		return 0;

	}

I followed this example:
1
2
z = subtraction (7,2);
cout << "The first result is " << z;

Stop. You're trying to learn too much, too soon. Just stop.

Learn how to write one function, and how to call it. Just one, but understand what you're doing.
yeah I'm looking for some easier stuff to practice now.
This is for my programming class though and due tonight so I may just have to take the hit because I'm getting no where.
My tutor didn't show up this week which stinks because the projects suddenly got harder.
Thanks for trying to help though, I appreciate it.
Topic archived. No new replies allowed.