Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Question about C++ programing homework

Posted on 2009-04-06
6
Medium Priority
?
287 Views
Last Modified: 2013-11-17
I am attempting to write a C++ program to count change.  For example if the bill amount is $56.23 and I was give $100.00 the change would be $43.77.  The program needs to figure out the number of 10 dollar 5 dollar and 1 dollar bills as well as the quarters nickles and dimes to give back.  I wrote the code below and it works until it calculates the quarters and then it starts to mess up.  An help would be great thanks  
#include <iostream>
using namespace ::std;
 
int main()
{
   float bill = 0;
   float paid = 0;
   int bill1 = 0;
   int paid1 = 0;
   int totalchange = 0;
   int changerm0 = 0;
   int changerm1 = 0;
   int changerm2 = 0;
   int changerm3 = 0;
   int changerm4 = 0;
   int changerm5 = 0;
   int changerm6 = 0;
   int numten = 0;
   int numfive = 0;
   int numone = 0;
   int numquarter = 0;
   int numdime = 0;
   int numnickel = 0;
   int numpenny = 0;
   cout << "Please Enter The Amount of the Bill: \n";
   cin >> bill;
   bill1 = bill*100;
   cout << "Please Enter The Amount paid: \n";
   cin >> paid;
   paid1 = paid*100;
   totalchange = (paid1 - bill1);
   numten = totalchange/1000;
   changerm0 = totalchange % 1000;
   numfive = changerm0/500;
   changerm1 = changerm0 % 500;
   numone = changerm1/100;
   changerm2 = changerm1 % 100;
   numquarter = changerm2/025;
   changerm3 = changerm2 % 025;
   numdime = changerm3/010;
   changerm4 = changerm3 % 010;
   numnickel = changerm4/005;
   changerm5 = changerm4 % 005;
   numpenny = changerm5/001;
   //changerm = q1%010;
   cout << "Give the customer the following change: \n";
   cout << bill1 <<" \n";
   cout << paid1 <<" \n";
   cout << totalchange <<" \n";
   cout << numdime << " $10 bills. \n";
   cout << changerm0 << " changerm0. \n";
   cout << numnickel << " $5 bills. \n";
   cout << changerm1 << " changerm1. \n";
   cout << changerm2 << " changerm2. \n";
   cout << changerm3 << " changerm3. \n";
   cout << changerm4 << " changerm4. \n";
   cout << changerm5 << " changerm5. \n";
   cout << numone << " $1 bills. \n";
   cout << numquarter << " quarters. \n";
   cout << numdime << " dimes. \n";
   cout << numnickel << " nickles. \n";
   cout << numpenny << " pennies. \n";
   cout << "Have a nice day: \n";
   system("\npause");
   return 0;
}

Open in new window

0
Comment
Question by:jaturley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24082235
>> and then it starts to mess up

Can you clarify, or do you expect us to run your program and find out what you mean? :)
0
 

Expert Comment

by:Laurual
ID: 24082729
Here you go. Fixed some minor errors, see comments
#include <iostream>
using namespace ::std;
 
int main()
{
   float bill = 0;
   float paid = 0;
   int bill1 = 0;
   float paid1 = 0;			//changed to float
   float totalchange = 0;   //changed to float
   int changerm0 = 0;
   int changerm1 = 0;
   int changerm2 = 0;
   int changerm3 = 0;
   int changerm4 = 0;
   int changerm5 = 0;
   int changerm6 = 0;
   int numten = 0;
   int numfive = 0;
   int numone = 0;
   int numquarter = 0;
   int numdime = 0;
   int numnickel = 0;
   int numpenny = 0;
   cout << "Please Enter The Amount of the Bill: \n";
   cin >> bill;
   bill1 = bill*100;
   cout << "Please Enter The Amount paid: \n";
   cin >> paid;
 
   paid1 = paid*100;
   totalchange = bill1 - paid1;  //use this or abs()
 
   numten = totalchange/1000;
 
   changerm0 = (int)totalchange % 1000;
   numfive = changerm0/500;
   changerm1 = changerm0 % 500;
   numone = changerm1/100;
   changerm2 = changerm1 % 100;
 
   numquarter = changerm2/25;
   changerm3 = changerm2 % 25;
 
   numdime = changerm3/10;
   changerm4 = changerm3 % 10;
   numnickel = changerm4/5;
   changerm5 = changerm4 % 5;
   numpenny = changerm5/1;
   //changerm = q1%010;
   cout << "Give the customer the following change: \n";
   cout << bill1 <<" \n";
   cout << paid1 <<" \n";
   cout << totalchange <<" \n";
   cout << numten << " $10 bills. \n";	//wrong var, changed to numten
   cout << changerm0 << " changerm0. \n";
   cout << numfive << " $5 bills. \n";	//wrong var, changed to numfive
   cout << changerm1 << " changerm1. \n";
   cout << changerm2 << " changerm2. \n";
   cout << changerm3 << " changerm3. \n";
   cout << changerm4 << " changerm4. \n";
   cout << changerm5 << " changerm5. \n";
   cout << numone << " $1 bills. \n";
   cout << numquarter << " quarters. \n";
   cout << numdime << " dimes. \n";
   cout << numnickel << " nickles. \n";
   cout << numpenny << " pennies. \n";
   cout << "Have a nice day: \n";
   system("\npause");
   return 0;
}

Open in new window

0
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24082764
How does your program malfunction?
0
 
LVL 1

Accepted Solution

by:
jefftope earned 2000 total points
ID: 24085067
The real issue is that entering the numbers 010 (= 8) 025 (=21) 005 (=5) will assume octal. Dont prefix numbers unless you need to.
0
 

Author Closing Comment

by:jaturley
ID: 31567269
Yes, I figured that out last night.  Thanks for the help.  I will be more discriptive with my issues in the future.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question