470,632 Members | 2,554 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,632 developers. It's quick & easy.

coin counting program

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 <iostream> //----->Header file
#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_val = quarter_value * num_quarters;
int total_dime_val = dime_value * num_dimes;
int total_nickel_val = nickel_value * num_nickels;
int total_pennies_val = pennies_value * num_pennies;

char full_name[32],
date[12];

cout << "Please Enter Your Name: ";
cin >>full_name;
cout <<endl;
cout << "Please Enter Today's Date: ";
cin >>date;
cout <<endl;
cout << "Enter the Number of Quarters: ";
cin >>num_quarters;
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+num_dimes+num_nickels +num_pennies;
//total_val_coins=quarter_value+dime_value+nickel_va lue+pennies_value;

//Total of each coin
//total_quarter_val= quarter_value*num_quarters;
//total_dime_val=dime_value*num_dimes;
//total_nickel_val=nickel_value*num_nickels;
//total_pennies_val=pennies_value*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_val <<endl;
cout <<"Dimes:" << total_dime_val <<endl;
cout <<"Nickels:" << total_nickel_val <<endl;
cout <<"Pennies:" << total_pennies_val <<endl <<endl;

cout <<"Total Value of coints:" <<total_val_coins <<endl <<endl;

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




#include <iostream> //----->Header file
#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_val;
double total_dime_val;
double total_nickel_val;
double total_pennies_val;
double total_val_coins;
char full_name[32],
date[12];

cout << "Please Enter Your Name: ";
cin >>full_name;
cout <<endl;
cout << "Please Enter Today's Date: ";
cin >>date;
cout <<endl;
cout << "Enter the Number of Quarters: ";
cin >>num_quarters;
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+num_dimes+num_nickels +num_pennies;
//total_val_coins=quarter_value+dime_value+nickel_va lue+pennies_value;

//Total of each coin
//total_quarter_val= quarter_value*num_quarters;
//total_dime_val=dime_value*num_dimes;
//total_nickel_val=nickel_value*num_nickels;
//total_pennies_val=pennies_value*num_pennies;
//total_val_coins = total_quarter_val + total_dime_val + total_nickel_val + total_pennies_val;
total_val_coins = (quarter_value*num_quarters) + (dime_value*num_dimes) + (nickel_value*num_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*num_quarters <<endl;
cout <<"Dimes:" << dime_value*num_dimes <<endl;
cout <<"Nickels:" << nickel_value*num_nickels <<endl;
cout <<"Pennies:" << pennies_value*num_pennies <<endl <<endl;
cout <<"Total Value of coins:" <<total_val_coins <<endl;
return 0;
}
May 5 '06 #2
[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
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

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Jon Monteleone | last post: by
52 posts views Thread by celerysoup16 | last post: by
5 posts views Thread by sallyk57 | last post: by
6 posts views Thread by karafire2003 | last post: by
3 posts views Thread by Jamie88 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.