how to put decimal point

So, I'm trying to figure out how to put a decimal point in my balance.
My program has increments for cents, dimes, dollars, and tens of dollars.
For example,
If 'a1' (cents) is entered = $.01
If 's3' (dimes) is entered = $.31
If 'd6' (dollars) is entered = $6.31

here is the output:
http://prntscr.com/dhip75

Here is my code:
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
  #include <iostream>
#include "redcounter.h"		
//* Library needed *//

using namespace std;

// Start of main function //
int main()
{
GroceryCounter counter;			// class of red little counter
int x = counter.count;			// count for the digits entered
int y = counter.count;			
char input[2], choice;			// input and choice for the increment

cout << "Welcome to Mom's Grocery Counter!" << endl;
	cout << "Enter your money using letters a, s, d, f, or o. ";
	cout << "This follows by the number 1-9." << endl;
	cout << "Use a for cents, s for dimes, d for dollars, and f for tens of dollars." << endl;
	cout << "Enter x to do another calculation." << endl;
	cout << "Example: s8" << endl;
do {
	cout << endl;
	cout << "Enter input: ";		// asked user to enter input
	cin >> input;

int x = 0;
y = input[1] - '0';
switch (input[0])			// switch statement to input cents, dimes, dollars and tens of dollars
{

	case 'a':
	case 'A':
		for (x = 0; x < y; x++)
		{
		
			counter.increment1();			// cents
		}
		if (counter.overflow())
		{
			counter.reset();
		}
		break;
	case 's':
	case 'S':
		for (x = 0; x < y; x++)
		{
			counter.increment10();			// dimes
		}
		if (counter.overflow())
		{
			counter.reset();
		}
		break;
	case 'd':
	case 'D':
		for (x = 0; x < y; x++)
		{
			counter.increment100();			// dollars
			
		}
		if (counter.overflow())
		{
			counter.reset();
		}
		break;
	case 'f':
	case 'F':
		for (x = 0; x < y; x++)
		{
			counter.increment1000();
		}									// tens of dollars
		if (counter.overflow())
		{
			counter.reset();
		}
		break;
	case 'r':
	case 'R': 
		{
			counter.reset();				// resets balance
		}
	default:
		break;
}


cout << "Your balance is $" << counter.count << endl;

cin >> choice;
}while (choice == 'x' || choice == 'X');			// press x to do another
system("pause");
return 0;
} 





GroceryCounter::GroceryCounter()
{
	count = 0;
	maxCount = 9999;
}
GroceryCounter::GroceryCounter(int value)
{
	maxCount = value;
	count = 0;
}
void GroceryCounter::reset()			// reset function
{
	count = 0;
}
void GroceryCounter::increment1()		// increase cents by 1
{
	count += 1;
}
void GroceryCounter::increment10()		// increase dimes by 10
{
	count += 10;
}
void GroceryCounter::increment100()		// increase dollars by 100
{
	count += 100;
}
void GroceryCounter::increment1000()	// increase tens of dollars by 1000
{
	count += 1000;
}
bool GroceryCounter::overflow()			// overflow function
{
	if (count > maxCount)
	{
		cout << "Overflow has occured. Your balance has been resetted. Press x to start over or press any key to exit." << endl;
		return true;
	}
	return false;
}

Last edited on
change your variable to double
It didn't do anything.

Enter input: a1
Your balance is $1
x

Shouldn't this output $0.01?

Enter input: a1
Your balance is $1
x

Enter input: s3
Your balance is $31
x

Shouldn't this output $0.31?

When you're calling incrementN(), you're treating count as if it were in cents. To convert cents to dollars, you'll need to divide by 100. This will give the correct output. Note that integer division will truncate the fractional part.
I got it to worked. Thanks!
Topic archived. No new replies allowed.