Ok, really really new at programming, so I'm trying to get a head start for a C++ class I'll be taking in the June. I have some exercises that I'm trying to go threw to practice. Once I figure out the program I want to try an enhance it.
The activity is:
Take an undetermined amount of pennies and have the program display how many pennies, nickels, dimes, quarters, 5, 10, 20, 100 dollar bills you will receive. The math is killing me even though I know it should be simple. I did some research and it looks like I should be using modular arithmetic (not familiar with that). Can anyone help me? I want to figure this out, so I can enhance it. I want to have it display how much Euro it would be as well, not sure how to do that yet.
have you already started with the prog? If so post what you have and we will try to help you to improve your prog.
the prog should (just a very rough outline)
- read dollar amount to be split
- subtract largest possible bill/coin and count how often you do this for each (do it till you reach zero)
- display result
- do the conversion to Euro (?? when and which value will you convert to euro)
if there are no special limitations to the coins/bills there should be no complex arithmetic involved.
leflon
0
super_man_1976Author Commented:
I have not started yet, just in my head. I don't have a compiler at work so I'll have to wait till I get home. I really confused my self when thinking about the simple math part. I must be overthinking it. As far as the Euro thing, I'm not sure. I don't have to do that, I just want to do something to extend on the basic part of the program, not sure what.
Right, I understand that.
Just to give you an idea on how new I am to programming and C++, below was my first program that I did last night. I will start programming this next exercise and post it as soon as I can. It's not for a formal class, just practice so I'm not lost when I do take a class. Thank you. for your help.
#include <iostream.h>
int main ()
{
int num1, num2, total;
num1 = 12;
num2 = 33;
total = num1 + num2;
cout << "The total of " <<num1 <<" and " << num2 << " is " <<
total << endl;
that's a fine start. looks much better than my first (the typical "Hello World")
just one thing to mention.
when you like to use the 'pure' C++ you should omit the old style includes <*.h>
your prog would start like
#include <iostream> // whithout .h
using namespace std; // so you can use cout and endl without the compiler throwing errors
int main ()
{
int num1, num2, total;
...
cout << "The total of " <<num1 <<" and " << num2 << " is " <<
total << endl;
return 0;
}
cheers
leflon
0
super_man_1976Author Commented:
Ok,
leflon this is what I have so far. I know, you can laugh out load I'll really unsure here. Is the //.. just to make a comment? Because that's what I was trying to do. If I'm heading in the right direction then I need to figure out the math part. So I should use Modulus (%) to give give me the remainder?
//... This program will calculate any amount of pennies into the following:
//... $100 Dollar Bills
//... $50 Dollar Bills
//... $20 Dollar Bills
//... $10 Dollar Bills
//... $5 Dollar Bills
//... $1 Dollar Bills
//... Quarters
//... Dimes
//... Nickles
//... Left over pennies
#include<iostream>
main()
{
{
cout<<"\n \n "This program will calculate your pennies so you know what to expect when exchanging them at the Bank!";
cout<<"How many Pennies do you have?:";
cin>>Pennies;
}
????Modulus (% in C++) should give give you the remainder???
cout<<"\n\n I've determned that this is what you should receive when you go to the bank:";
Ok, this is what I have now. I think the math is closer???????
//... This program will calculate any amount of Pennies into the following:
//... 100 Dollar Bills
//... 50 Dollar Bills
//... 20 Dollar Bills
//... 10 Dollar Bills
//... 5 Dollar Bills
//... 1 Dollar Bills
//... Quarters
//... Dimes
//... Nickles
//... Remaining pennies
#include<iostream>
main()
{
{
cout<<"\n \n "This program will calculate your Pennies so you know what to expect when exchanging them at the Bank!";
cout<<"How many Pennies do you have?:";
cin>>Pennies;
int One Hundred Dollar Bills = Pennies / 10000;
int Fifty Dollar Bills = Pennies / 5000;
int Pennies = Pennies % 5000;
int Twenty Dollar Bills = Pennies / 2000;
int Pennies = Pennies % 2000;
int Ten Dollar Bills = Pennies / 1000;
int Pennies = Pennies % 1000;
int Five Dollar Bills = Pennies / 500;
int Pennies = Pennies % 500;
int One Dollar Bills = Pennies / 100;
int Pennies = Pennies % 100;
int Quarters = Pennies / 25;
int Pennies = Pennies % 25;
int Dimes = Pennies / 10;
int Pennies = Pennies % 10;
int Nickles = Pennies / 5;
int Pennies = Pennies % 5;
int Pennies = 1;
int Pennies = Pennies % 1;
cout<<"\n\n I've determned that this is what you should receive when you go to the bank:";
cout<<int
i think the basic idea is ok.
you ask the user to input the ammount of pennies and then get the amount of each bill/coin by doing an integer division and you get the still to distribute rest by doing the modulo operation.
but there are a few errors in the code.
1. the variable Pennies is not defined
2. variable names with spaces in it (One Hundred Dollar Bills etc.) are not allowed. make it OneHundredDollarBills
3. do not redefine Pennie in each modulo operation (int Pennies=Pennies%5000 => Pennies=Pennies%5000)
4. you forgot (either in your prog or just in your post here) the modulo operation for the hundret dollar bills.
5. there seems to be a missing closing bracket '}' at the end of the prog. (you can omit the inner pair of { }.
6. you don't need the last modulo op, cause what is left after %5 should be the amount of single pennies.
so you have something like
int main(int argc, char* argv[])
{
int Pennies = 0;
int OrgPennoes = 0; // for storiung the original amount of pennies
// your initial output, program description etc.
cin >> Pennies;
// here you may want to insert some error handling if user enters wrong values (like 'aaaa')
OrgPennies = Pennies,
// now comes the splitting, the way you supposed to do
int Bill100 = Pennies/10000;
Pennies = Pennies%10000;
... // allthe other bills and coins
// at this point you have your Pennies divided into the different bills and coins and have stored the amount of each in the proper var
// now we have to do the output
cout << "For " << OrgPennies << " you will get:" << endl;
cout << Bill100 << "onehundret dollar bills" << endl;
...// all the other bills and coins
cout << Pennies << "pennies" << endl;
return 0; // program end
}
for the first shot the prog shall do what you want it to do, but you may like to add some error checking or make it a litlle shorter (and some say more readable) by adding some other stuff like using arrays etc.
hth
leflon
0
super_man_1976Author Commented:
Ok, first of all I want to thank you for all the help. :) I'm learning on the fly here.
Here is what I have so far, thought I was headed in the write direction until I tried compileing it with 1 error. Not sure what it is.
int main
{
int Pennies = 0;
int OrgPennoes = 0;
// This program will calculate any amount of Pennies into: $100's, $50's, $20's, $10's , $5's, 1's, Quarters, Dimes, Nickles and the remaining pennies.
cin >> Pennies;
// Possible error handling.
OrgPennies = Pennies,
// Splitting up the money
int Bill100 = Pennies/10000;
Pennies = Pennies%10000;.
int Bill50 = Pennies/5000;
Pennies = Pennies%5000;.
int Bill20 = Pennies/2000;
Pennies = Pennies%2000;.
int Bill10 = Pennies/1000;
Pennies = Pennies%1000;.
int Bill5 = Pennies/500;
Pennies = Pennies%1000;.
int Bill1 = Pennies/100;
Pennies = Pennies%100;.
int Coin25 = Pennies/25;
Pennies = Pennies%25;.
int Coin10 = Pennies/10;
Pennies = Pennies%10;.
int Coin5 = Pennies/5;
Pennies = Pennies%5;.
int Coin1 = Pennies/1;
Pennies = Pennies%1;.
cout << "For " << OrgPennies << " You will get:" << endl;
cout << Bill100 << "One Hundred dollar bills" << endl;
you have a typo in OrgPennies declaration -> int OrgPennoes = 0;
this will give you a syntax error (something like undeclared.....) for the line ->
OrgPennies = Pennies, (and here is a ',' where a ';' has to be)
and
cout << "For " << OrgPennies << " You will get:" << endl;
have you already started with the prog? If so post what you have and we will try to help you to improve your prog.
the prog should (just a very rough outline)
- read dollar amount to be split
- subtract largest possible bill/coin and count how often you do this for each (do it till you reach zero)
- display result
- do the conversion to Euro (?? when and which value will you convert to euro)
if there are no special limitations to the coins/bills there should be no complex arithmetic involved.
leflon