I need help with C++

MegaloJntariac
10+ year member

Mr.SQ
Here is where I am at now. I can get it to execute, but its:

- Not taking the fee out and posting it

- Its only changing bills but not with the coins, and if i input just a decimal it shows the coins, so i need it to do both.

Win32 Console file

Code:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

void change(double, int&, int&, int&, int&, int&, int&);
void change(double, int&, int&, int&, int&);  




bool validFee(double a)
{
return (a <= 1000);
} // end Bool
void main()
{
int quar=0, dime=0, nick=0, penn=0, hunds = 0, fifts= 0, twents = 0, tens = 0, fives = 0, ones = 0;
double a;    //price of check < $1000.01

do
{
cout<<"Enter Check Amount: ";
cin>>a;
}
while (! validFee(a));

cout<<"Check Amount:                          "<<a<<endl;



change(a, hunds, fifts, twents, tens, fives, ones);
change(a,  quar, dime, nick, penn);



}//endmain

double fee(double& a)
{


if (a>=0 && a<=100)
{
	a = a - 5;
	cout<<" Cashing Fee :              $5.00"<<endl;
	return a;
} // ends if
if (a>100 && a<=500)
{
	a = a - 15;
	cout<<" Cashing Fee :$15.00"<<endl;
	return a;
} // ends if

if (a>500 && a<=1000)
{
	a = a - 25;
	cout<<" Cashing Fee :$25.00"<<endl;
	return a;
} // ends if



}//end fee


void change(double a,int& h,int& f,int& tw,int& te,int& fi,int& o)
{
int c = static_cast<int>(a);
int hunds, fifts, twents, tens, fives, ones;

h=c/100;
c%=100;
f=c/50;
c%=50;
tw=c/25;
c%=25;
te=c/10;
c%=10;
fi=c/5;
c%=5;
o=c/1;

hunds = (h) * 100;
fifts = (f) * 50;
twents = (tw) * 20;
tens = (te) * 10;
fives = (fi) * 5;
ones = (o) * 1;



cout<<"Denominations Dispensed:"<<setw(15)<<endl;
cout<<"------------------------"<<setw(15)<<endl;
cout<<"	               #       Amount"<<setw(15)<<endl;
cout<<"	             ------   -------- "<<setw(10)<<endl;
if(h>0)
	cout<<"Hundreds: "<<setw(15)<<h<<setw(10)<<hunds<<endl;
if(f>0)
	cout<<"Fifties:  "<<setw(15)<<f<<setw(10)<<fifts<<endl;
if(tw>0)
	cout<<"Twenties: "<<setw(15)<<tw<<setw(10)<<twents<<endl;
if(te>0)
	cout<<"Tens:     "<<setw(15)<<te<<setw(10)<<tens<<endl;
if(fi>0)
	cout<<"Fives:    "<<setw(15)<<fi<<setw(10)<<fives<<endl;
if(o>0)
	cout<<"Ones:     "<<setw(15)<<o<<setw(10)<<ones<<endl;

} // end change bills 
void change(double a,int& q,int& d,int& n,int& p)
{	double chg = 1.00 - a;
int quar, dime, nick, penn;

int c = static_cast<int> (chg*100);

q=c/25;
c%=25;
d=c/10;
c%=10;
n=c/5;
p=c%5;

quar = (q) * 25;
dime = (d) * 10;
nick = (n) * 05;
penn = (p) * 01;

if(q>0)
	cout<<"Quarters: "<<setw(15)<<q<<setw(10)<<quar<<endl;
if(d>0)
	cout<<"Dimes:    "<<setw(15)<<d<<setw(10)<<dime<<endl;
if(n>0)
	cout<<"Nickels:  "<<setw(15)<<n<<setw(10)<<nick<<endl;
if(p>0)
	cout<<"Pennies:  "<<setw(15)<<p<<setw(10)<<penn<<endl;




} // end change coins
Here is what I am trying to get it to do:

- Prompts to ask for Check amount

- You Input check amount, if it is more than 1000 it loops back and asks you again

- at this point it should take a fee out based on the amount, also it will tell you how much the fee was

- now it should take whats left after the fee and change that into bills and coins, but our instructor wanted us to use an overload function to separate the bills and coins but using the same name.

 
So you want to call coins and dollars with the same variable? Thats what I get from the last line of the OP. If so it wont work. The last value to be input for that specific variable is what will display there.

 
So you want to call coins and dollars with the same variable? Thats what I get from the last line of the OP. If so it wont work. The last value to be input for that specific variable is what will display there.
You can do function overloading from what I understand, our instructor told us to function overload it, as long as the argument is different it should work....maybe I overlooked something? Any suggestions?

 
Looks right to me. It could be something as simple as indenting that is throwing the code off. I know when I worked with Python an indent made a huge difference. Other than that I dont see where your using the same variable twice for the overload. Maybe make sure you have everything spelled right and are using the same variables for what you have to.

 
Okay I tried doing this but I ended up with unidentified errors:

Code:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

double fee(double& a); 
int change(double, int&, int&, int&, int&, int&, int&);
int change(double, int&, int&, int&, int&);  
void display(int& ,int& ,int&,int&, int&, int&, int&, int&, int&,int&,int&,int&,int&,int&,int&,int&,int&,int&,int&,int&);






bool validFee(double a)
{
return (a <= 1000);
} // end Bool
void main()
{
int quar=0, dime=0, nick=0, penn=0, hunds = 0, fifts= 0, twents = 0, tens = 0, fives = 0, ones = 0;
double a;    //price of check < $1000.01

do
{
cout<<"Enter Check Amount: ";
cin>>a;
}
while (! validFee(a));

cout<<"Check Amount:                          "<<a<<setprecision(2)<<endl;


fee(a);

change(a, hunds, fifts, twents, tens, fives, ones);
change(a,  quar, dime, nick, penn);
display(q,d,n,p, quar, dime, nick, penn, hunds,fifts,twents,tens,fives,ones,h,f,tw,te,fi,o);





}//endmain

double fee(double& a)
{


if (a>=0 && a<=100)
{
	a = a - 5;
	cout<<" Cashing Fee :              $5.00"<<endl;
	return a;
} // ends if
else if (a>100 && a<=500)
{
	a = a - 15;
	cout<<" Cashing Fee :$15.00"<<endl;
	return a;
} // ends if

else 
{
	a = a - 25;
	cout<<" Cashing Fee :$25.00"<<endl;
	return a;
} // ends if



}//end fee


int change(double a,int& h,int& f,int& tw,int& te,int& fi,int& o)
{
int c = static_cast<int>(a);
int hunds, fifts, twents, tens, fives, ones;

h=c/100;
c%=100;
f=c/50;
c%=50;
tw=c/25;
c%=25;
te=c/10;
c%=10;
fi=c/5;
c%=5;
o=c/1;

hunds = (h) * 100;
fifts = (f) * 50;
twents = (tw) * 20;
tens = (te) * 10;
fives = (fi) * 5;
ones = (o) * 1;

return (hunds,fifts,twents,tens,fives,ones,h,f,tw,te,fi,o);



} // end change bills 
int change(double a,int& q,int& d,int& n,int& p)
{	double chg = 1.00 - a;
int quar, dime, nick, penn;

int c = static_cast<int> (chg*100);

q=c/25;
c%=25;
d=c/10;
c%=10;
n=c/5;
p=c%5;

quar = (q) * 25;
dime = (d) * 10;
nick = (n) * 05;
penn = (p) * 01;

return( q,d,n,p, quar, dime, nick, penn);



} // end change coins

void display(int& q,d,n,p, quar, dime, nick, penn, hunds,fifts,twents,tens,fives,ones,h,f,tw,te,fi,o)
{


cout<<"Denominations Dispensed:"<<setw(15)<<endl;
cout<<"------------------------"<<setw(15)<<endl;
cout<<"	               #       Amount"<<setw(15)<<endl;
cout<<"	             ------   -------- "<<setw(10)<<endl;
if(h>0)
	cout<<"Hundreds: "<<setw(15)<<h<<setw(10)<<hunds<<endl;
if(f>0)
	cout<<"Fifties:  "<<setw(15)<<f<<setw(10)<<fifts<<endl;
if(tw>0)
	cout<<"Twenties: "<<setw(15)<<tw<<setw(10)<<twents<<endl;
if(te>0)
	cout<<"Tens:     "<<setw(15)<<te<<setw(10)<<tens<<endl;
if(fi>0)
	cout<<"Fives:    "<<setw(15)<<fi<<setw(10)<<fives<<endl;
if(o>0)
	cout<<"Ones:     "<<setw(15)<<o<<setw(10)<<ones<<endl;

if(q>0)
	cout<<"Quarters: "<<setw(15)<<q<<setw(10)<<quar<<endl;
if(d>0)
	cout<<"Dimes:    "<<setw(15)<<d<<setw(10)<<dime<<endl;
if(n>0)
	cout<<"Nickels:  "<<setw(15)<<n<<setw(10)<<nick<<endl;
if(p>0)
	cout<<"Pennies:  "<<setw(15)<<p<<setw(10)<<penn<<endl;

}
Code:
Compiling...
Program_6.cpp
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(40) : error C2065: 'q' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(40) : error C2065: 'd' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(40) : error C2065: 'n' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(40) : error C2065: 'p' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(40) : error C2065: 'h' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(40) : error C2065: 'f' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(40) : error C2065: 'tw' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(40) : error C2065: 'te' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(40) : error C2065: 'fi' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(40) : error C2065: 'o' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(130) : error C2061: syntax error : identifier 'd'
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(138) : error C2065: 'h' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(139) : error C2065: 'h' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(139) : error C2065: 'hunds' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(140) : error C2065: 'f' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(141) : error C2065: 'f' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(141) : error C2065: 'fifts' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(142) : error C2065: 'tw' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(143) : error C2065: 'tw' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(143) : error C2065: 'twents' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(144) : error C2065: 'te' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(145) : error C2065: 'te' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(145) : error C2065: 'tens' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(146) : error C2065: 'fi' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(147) : error C2065: 'fi' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(147) : error C2065: 'fives' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(148) : error C2065: 'o' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(149) : error C2065: 'o' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(149) : error C2065: 'ones' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(152) : error C2065: 'quar' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(153) : error C2065: 'd' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(154) : error C2065: 'd' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(154) : error C2065: 'dime' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(155) : error C2065: 'n' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(156) : error C2065: 'n' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(156) : error C2065: 'nick' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(157) : error C2065: 'p' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(158) : error C2065: 'p' : undeclared identifier
c:\documents and settings\macbook\my documents\program_6\program_6\program_6\program_6.cpp(158) : error C2065: 'penn' : undeclared identifier
Build log was saved at "file://c:\Documents and Settings\Macbook\My Documents\Program_6\Program_6\Program_6\Debug\BuildLog.htm"
Program_6 - 39 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I cant figure out how to declare that. my logic is off. and I dont know where

 
IO in c++ is alot simpler than java. Java you have to use the java VM.

OP I'll write the entire program for you for $50, pm me if you want. Its too hard to try and follow someone elses logic to debug

 
Activity
No one is currently typing a reply...

About this thread

MegaloJntariac

10+ year member
Mr.SQ
Thread starter
MegaloJntariac
Joined
Location
3 Octaves Lower
Start date
Participants
Who Replied
Replies
11
Views
254
Last reply date
Last reply from
Hundreth
IMG_20260516_193114554_HDR.jpg

sherbanater

    May 16, 2026
  • 0
  • 0
IMG_20260516_192955471_HDR.jpg

sherbanater

    May 16, 2026
  • 0
  • 0

New threads

Top