I am trying to learn C++ by myself using a book and want to work through everything it says. I am on a program that you have to write kinda like a cash register program that tells you how many 5's, 1's, quarters, dimes, nickles, and pennies you should get back. It wants you to create a seperate function to do the calculations. I am really lost. I have bits and pieces, but I don't know what to do. I've been going on this for about 6 hours now trying to figure stuff out and ended up just starting over a bunch of times cause it was just completely wrong. The code I have is below, but I don't know what to do from here. Any help would be GREATLY appreciated. Thank you so much.

#include <iostream>
#include <conio.h>
#include <iomanip>
using namespace std;
float calcchange(float, float, float, float, float, float, float);  //function prototype
int main ()

{
	float  ftotal = 0,
		   fcents = 0,
		   fchange = 0,
           ffives = 0,
		   fones= 0,
		   fquarters = 0,
		   fdimes = 0,
		   fnickles = 0,
		   fpennies = 0;
		  

	cout << "   ~~~~~~~~Payroll Calculator ~~~~~~~~~~" << endl;
	cout << "Enter the total price: ";
	cin >> ftotal;
	
	


	//fpay = fhours * frate;
	fchange = calcPay(ftotal,ffives,fones,iquarters,);  // call function and send to arguments
	cout << "The total pay is $" << setprecision(2) << fixed
		 << fpay << endl; 

	cout << "any key..." << endl;
	_getch();
	return 0;
}
float calcPay(float h, float r)
{
	// compute the change
    while (cents >= 25) {
          quarters++;
          cents -= 25;
    }
    while (cents >= 10) {
          dimes++;
          cents -= 10;
    }
    while (cents >= 5) {
          nickels++;
          cents -= 5;
    }
    while (cents >= 1) {
          pennies++;
          cents -= 1;
    }
}

Your calcPay function is never prototyped, so you can't call it from main (you do have a prototype for calcchange(), a function that is never declared, though).

Also, you never use the h and r parameters passed into calcPay. This isn't a syntax error, but it is probably not what you want to do.

And last of all, the values quarters, cents, dimes, nickels, and pennies, are not initialized inside off calcPay (or anywhere for that matter). And fpay in main is also not initialized or declared.

Your calcPay function is never prototyped, so you can't call it from main (you do have a prototype for calcchange(), a function that is never declared, though).

Also, you never use the h and r parameters passed into calcPay. This isn't a syntax error, but it is probably not what you want to do.

And last of all, the values quarters, cents, dimes, nickels, and pennies, are not initialized inside off calcPay (or anywhere for that matter)

Ya, I know, I had stuff in there and then I deleted it and then started looking at doing other stuff and I'm just so confused, I don't even know where to start on this program. I'm just lost and it seems like I'm in a black hole, so there is no light shining in any direction. If somebody could just kinda show me the direction I need to go even that would be a huge help. Thanks.

I would pass quarters, cents, dimes, nickels, and pennies into calcPay as a refrence, like float calcPay(float& quarters, float& cents, float& dimes, float& nickels, float& pennies); , then you should be able to modify them correctly in calcPay.

1) How can you have 2.4 dimes? Or 3.7 quarters? The values of the denominations only need to be integers.

2) Have you spent 6 hours sitting in front of the computer just whacking at the code hoping you get the right answer? If so, you are missing the most important part of programming. Writing out how to do what you need to do, changing it until you understand the process completely. Only then should you sit in front of the computer.

Writing a program is like taking a trip. The computer work is the driving part of the trip. But if you don't plan the route to where you are going, how can you ultimately reach the destination?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.