473,729 Members | 2,176 Online

# coin counting program

2 New Member
Help, im a student that has to write a program for counting coins. Half of the program works but the other half doesn.t

should have the following parameters.

output is:
Name
Date
total number of coins
number of quarters
number of dimes
nickels
pennies

I got all that to work but that math doesnt work

for the Value of the coins and the total coin value, can someone please tell me what im doing wrong?

#include <string.h>
#include <math.h>

void main()

{

double quarter_value(0 .25);
double dime_value(0.10 );
double nickel_value(0. 05);
double pennies_value(0 .01);

int num_quarters;
int num_dimes;
int num_nickels;
int num_pennies;
int total_num_coins ;
int total_val_coins = quarter_value + dime_value + nickel_value + pennies_value;
int total_quarter_v al = quarter_value * num_quarters;
int total_dime_val = dime_value * num_dimes;
int total_nickel_va l = nickel_value * num_nickels;
int total_pennies_v al = pennies_value * num_pennies;

char full_name[32],
date[12];

cin >>full_name;
cout <<endl;
cout << "Please Enter Today's Date: ";
cin >>date;
cout <<endl;
cout << "Enter the Number of Quarters: ";
cin >>num_quarter s;
cout <<endl;
cout << "Enter the Number of Dimes: ";
cin >>num_dimes;
cout <<endl;
cout << "Enter the Number of Nickels: ";
cin >>num_nickels ;
cout <<endl;
cout << "Enter the Number of Pennies: ";
cin >>num_pennies ;
cout <<endl;

//Total Number of Coins and Value

//total_num_coins =num_quarters+n um_dimes+num_ni ckels+num_penni es;
//total_val_coins =quarter_value+ dime_value+nick el_value+pennie s_value;

//Total of each coin
//total_quarter_v al= quarter_value*n um_quarters;
//total_dime_val= dime_value*num_ dimes;
//total_nickel_va l=nickel_value* num_nickels;
//total_pennies_v al=pennies_valu e*num_pennies;

cout <<"Name:" << full_name <<endl <<endl;

cout <<"Date:" << date <<endl <<endl;

cout <<"Total number of coins input:" << total_num_coins <<endl;
cout <<"Number of Quarters:" << num_quarters <<endl;
cout <<"Number of Dimes:" << num_dimes <<endl;
cout <<"Number of Nickels:" << num_nickels <<endl;
cout <<"Number of Pennies:" << num_pennies <<endl <<endl;

cout <<"Value of Coins:" <<endl;
cout <<"Quarters:" << total_quarter_v al <<endl;
cout <<"Dimes:" << total_dime_val <<endl;
cout <<"Nickels:" << total_nickel_va l <<endl;
cout <<"Pennies:" << total_pennies_v al <<endl <<endl;

cout <<"Total Value of coints:" <<total_val_coi ns <<endl <<endl;

return 0;
}
May 5 '06 #1
3 16927
mandogon
31 New Member
i got your program working i will send it to you and you can compare the changes that i made to you program

#include <string.h>
#include <math.h>
using namespace std;

int main()

{

double quarter_value(0 .25);
double dime_value(0.10 );
double nickel_value(0. 05);
double pennies_value(0 .01);

int num_quarters;
int num_dimes;
int num_nickels;
int num_pennies;
int total_num_coins ;

double total_quarter_v al;
double total_dime_val;
double total_nickel_va l;
double total_pennies_v al;
double total_val_coins ;
char full_name[32],
date[12];

cin >>full_name;
cout <<endl;
cout << "Please Enter Today's Date: ";
cin >>date;
cout <<endl;
cout << "Enter the Number of Quarters: ";
cin >>num_quarter s;
cout <<endl;
cout << "Enter the Number of Dimes: ";
cin >>num_dimes;
cout <<endl;
cout << "Enter the Number of Nickels: ";
cin >>num_nickels ;
cout <<endl;
cout << "Enter the Number of Pennies: ";
cin >>num_pennies ;
cout <<endl;

//Total Number of Coins and Value

total_num_coins =num_quarters+n um_dimes+num_ni ckels +num_pennies;
//total_val_coins =quarter_value+ dime_value+nick el_value+pennie s_value;

//Total of each coin
//total_quarter_v al= quarter_value*n um_quarters;
//total_dime_val= dime_value*num_ dimes;
//total_nickel_va l=nickel_value* num_nickels;
//total_pennies_v al=pennies_valu e*num_pennies;
//total_val_coins = total_quarter_v al + total_dime_val + total_nickel_va l + total_pennies_v al;
total_val_coins = (quarter_value* num_quarters) + (dime_value*num _dimes) + (nickel_value*n um_nickels) + (pennies_value* num_pennies);

cout <<"Name:" << full_name <<endl;

cout <<"Date:" << date <<endl;

cout <<"Total number of coins input:" << total_num_coins <<endl;
cout <<"Number of Quarters:" << num_quarters <<endl;
cout <<"Number of Dimes:" << num_dimes <<endl;
cout <<"Number of Nickels:" << num_nickels <<endl;
cout <<"Number of Pennies:" << num_pennies <<endl <<endl;

cout <<"Value of Coins:" <<endl;
cout <<"Quarters:" << quarter_value*n um_quarters <<endl;
cout <<"Dimes:" << dime_value*num_ dimes <<endl;
cout <<"Nickels:" << nickel_value*nu m_nickels <<endl;
cout <<"Pennies:" << pennies_value*n um_pennies <<endl <<endl;
cout <<"Total Value of coins:" <<total_val_coi ns <<endl;
return 0;
}
May 5 '06 #2
viewsonic
2 New Member
[quote=mandogon]i got your program working i will send it to you and you can compare the changes that i made to you program

Thank you so much, funny i was almost there just forgot to do the math, :p
May 6 '06 #3
HerHemi
1 New Member
Hello. I am new to Java and this forum. I have a similar assignment for coin counting....can someone help me?

Create a Java application that prompts a user for a dollar amount (such as 10.34) and then calculates the minimum number of pennies, nickels, dimes, quarters, dollar bills, five dollar bills, ten dollar bills, and twenty dollar bills that are needed to make up that amount. (Using the \$10.34 amount, it would take one ten dollar bill; one quarter; one nickel; and four pennies to make up this value.)
May 24 '06 #4