Short changed

closed account (ihT7X9L8)
I'm trying to create a simple change sorter program, everything is functioning properly expect for the part that's suppose to detect quarters.

Example of current output:

The amount you entered is: 52.50

You have this many Fifty dollars: 1

You have this many Ten dollars: 0

You have this many One: 2

You have this many Quarters: 0


Desired output:

The amount you entered is: 52.50

You have this many Fifty dollars: 1

You have this many Ten dollars: 0

You have this many One: 2

You have this many Quarters: 2




I can't figure out how to adjust this, so the quarters can be read.

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
#include <iostream>
#include <iomanip>

using namespace std;

const int FIFTY = 50;
const int TEN = 10;
const int ONE = 1;
const int QUARTER = 0.25;

int _tmain(int argc, _TCHAR* argv[])
{
	int change;

	cout << "Enter the amount of money in your wallet: ";


	cin >> change;


	cout << endl;



	cout << "The amount you entered is: " << change << endl;


	cout << "You have this many Fifty dollars: " << change / FIFTY << endl;
	change = change % FIFTY;

	//
	cout << "You have this many Ten dollars: " << change / TEN << endl;
	change = change % TEN;



	//
	cout << "You have this many One: " << change / ONE << endl;
	change = change % ONE;


	//
	cout << "You have this many Quarters: " << change / QUARTER << endl;
	change = change % QUARTER;



	return 0;
}


[Update] Still getting errors, even after changing the code based on feedback.

Lines [45-47] or the Quarter block must stay where it is, thought I did switch them and still got the same errors.

Those error codes by the way are:

Error 1 error C2297: '%' : illegal, right operand has type 'double'

Error2 IntelliSense: expression must have integral or unscoped enum type
Last edited on
Swap the order of lines [45, 47] with [41, 43]

Also, it's a good thing line 10 is never used, because that value is always zero.
closed account (ihT7X9L8)
That unfortunately didn't seem to help all that much, I'm still getting errors like this:

Error 1 error C2297: '%' : illegal, right operand has type 'double'


2 IntelliSense: expression must have integral or unscoped enum type


Did you delete line 18? If not, do so.
closed account (ihT7X9L8)
Yes, still getting the same errors LB
Could you repost your current code and copy and paste the errors you are getting?
closed account (ihT7X9L8)
Updated info
Do not use <conio.h> - it is not part of the C++ standard library.
https://en.wikipedia.org/wiki/Conio.h

When you changed your program from the way it was before, you seem to have misunderstood what was saying. Let me be clear this time: your program should not contain the keywords float or double at all.
closed account (ihT7X9L8)
Okay, it runs, but it either crashes or if it does run and the quarters don't appear.

Actually in both cases the quarters don't appear.

The quarters has always been the issue and it's the only thing keeping this program from being complete.
Post your current code.
closed account (ihT7X9L8)
Posted

By the way have you been running this code at any point?

Your line 9 is still wrong - just write "25" and not "0.25" like you did with the other values.
gotg1980 wrote:
By the way have you been running this code at any point?
It is non-standard (it does not have a main function) so how could I run it? It only works in your crazy Visual Studio IDE because Microsoft does weird things. I can, however, easily run modified versions of your program, but I don't need to because before I even consider running a program I look for glaring errors.
Last edited on
closed account (ihT7X9L8)
Okay, did that, sure it doesn't crash now, but it still doesn't read the quarters.
I just noticed you ignored my first reply - you never swapped lines [36-39] with [42-44].
Last edited on
closed account (ihT7X9L8)
I actually did change them and it did't make a difference, same result.
You need to decide whether TEN and FIFTY are -cent coins or -dollar bills.

This is your program assuming you meant -dollar bills:
http://ideone.com/gfVsaY
closed account (48T7M4Gy)
The problem with your program is due to the mixed units and using integer division causing roundoff errors.

A compatible set of units would be cents which means that you convert the dollar input to cents and work from there.
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
#include <iostream>
#include <conio.h>
#include <iomanip>

using namespace std;

const int FIFTY = 5000;
const int TEN = 1000;
const int ONE = 100;
const int QUARTER = 25;


int main()
{
    double amount;
    int change;

    cout << "Enter the amount of money in your wallet: ";

    cin >> amount;

    change = 100*amount;


    cout << endl << "The amount you entered is: " << change << endl;

    cout << "You have this many Fifty dollars: " << change / FIFTY << endl;
    change = change % FIFTY;
    //
    cout << "You have this many Ten dollars: " << change / TEN << endl;
    change = change % TEN;
    //
    cout << "You have this many One: " << change / ONE << endl;
    change = change % ONE;

    cout << "You have this many Quarters: " << change / QUARTER << endl;


    cout << "You have this many Cents: " << change % QUARTER << endl;
    _getch();

    return 0;
}
Topic archived. No new replies allowed.