[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

Mod Operator needs to be added? Help fixing C++ program using doubles

Asked by nuclearwerewolf in C++ Programming Language, C Programming Language, Microsoft Visual C++

Tags: Mod Operator help, Fix c++ program, Doubles

This question was asked previously but, to no avail.
I am using code blocks as my compiler.

I have a program that I am trying to figure out.
The instructions given is:
Write a C++ program will take in the price of an item purchased and  the amount of cash tendered. The program will output the amount of change and then break this down
into dollars, quarters, dimes, nickels and pennies.Use the modulus operator. You may be off by one penny, but see if
you can find a way to fix that by writing code to perform rounding.  When you assign a double to an int, the decimal
portion is truncated.

Example run:

Enter the price of the item:   3.35

Enter the amount of cash tendered: 5.00

Your change is $1.65

1 dollar
2 quarters
1 dimes
1 nickel
0 pennies

Please help me figure out how to implement the mod operator and get the correct change.

I asked this question previously and the expert didn't give answer using double.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
**************
**************
 
Original Code:
#include <iostream>
 
using namespace std;
 
int main()
{
    double itemPrice;
    double cashTendered;
    double change;
    int dollars ;
    int quarters ;
    int dimes ;
 
    cout << " What was the price of the item purchased ?" ;
    cin >> itemPrice;
 
    cout << " How much did you hand the cashier ?" ;
    cin >> cashTendered;
 
    change = cashTendered - itemPrice;
    dollars = change ;
    quarters = (change - dollars) / .25;
    dimes = (change - dollars) / .10 ;
 
 
 
 
    cout << " Your change should be :$" << change << endl ;
    cout << dollars << "Dollar(s)" << endl;
    cout << quarters << "Quarter(s)" << endl;
    cout << dimes << " Dime(s)" << endl ;
 
    return 0;
}
 
 
************
************
Expert Code (not compilable and without doubles):
 float itemPrice;
    float cashTendered;
    float change;
    int dollars ;
    int quarters ;
    int dimes ;
      int nickels;
      int pennies;
      int temp;
      dollars = quarters = dimes = nickels = pennies = 0;
 
    cout << " What was the price of the item purchased ?" ;
    cin >> itemPrice;
 
    cout << " How much did you hand the cashier ?" ;
    cin >> cashTendered;
 
   /* change = cashTendered - itemPrice;
    dollars = change ;
 
      temp = change-dollars;
    quarters = (change - dollars) / 0.25;
   
      dimes = (temp - quarters*0.25) / 0.10 ;
    
      temp = temp - (dimes*0.10)- (quarters*0.25);
      
    nickels = temp/0.05;
 
      temp = temp - (nickels*0.05) ;
 
    pennies = temp/0.01;*/
 
    change = cashTendered - itemPrice;
    dollars = change ;
    temp = (change-dollars)*100;
    //temp = temp*100;
    quarters = (temp - (temp % 25 ))/25;
      temp = temp - (25 * quarters);
    dimes = (temp - (temp % 10))/10;
    temp = temp - (10 * dimes);
      nickels = (temp - (temp % 5))/5;
      pennies = temp - (5 * nickels);
 
 
 
 
 
    cout << " Your change should be :$" << change << endl ;
    cout << dollars << " Dollar(s)" << endl;
    cout << quarters << " Quarter(s)" << endl;
    cout << dimes << " Dime(s)" << endl ;
    cout << nickels << " nickel(s)" << endl ;
    cout << pennies << " pennie(s)" << endl ;
 
Related Solutions
Keywords: Mod Operator needs to be added? Hel…
 
Loading Advertisement...
 
[+][-]09/19/09 01:23 AM, ID: 25372049Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: C++ Programming Language, C Programming Language, Microsoft Visual C++
Tags: Mod Operator help, Fix c++ program, Doubles
Sign Up Now!
Solution Provided By: TheCatcher
Participating Experts: 2
Solution Grade: A
 
[+][-]09/19/09 12:15 AM, ID: 25371856Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]09/19/09 12:16 AM, ID: 25371859Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/19/09 12:20 AM, ID: 25371872Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/19/09 12:21 AM, ID: 25371877Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/19/09 12:29 AM, ID: 25371905Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/19/09 12:33 AM, ID: 25371914Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/19/09 12:35 AM, ID: 25371919Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/19/09 12:39 AM, ID: 25371930Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/19/09 12:47 AM, ID: 25371955Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/19/09 12:52 AM, ID: 25371972Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/19/09 12:58 AM, ID: 25371987Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/19/09 01:01 AM, ID: 25371993Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/19/09 01:16 AM, ID: 25372030Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/19/09 01:36 AM, ID: 25372081Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/19/09 02:18 AM, ID: 25372185Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/19/09 02:20 AM, ID: 25372193Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091118-EE-VQP-93 - Hierarchy / EE_QW_3_20080625