Decimals?

Hey guys and gals. Pretty new to C++. I'm writing a program where a user inputs certain hours and at the very end, it will display how much money you will make. Can't seem to make it put decimals. Code below:

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

using namespace std;

int main ( )

{
    int a, b, c, d, e, sum;


    cout << "How many hours did you work on Monday:";
    cin >> a;
    cout << "How many hours did you work on Tuesday:";
    cin >> b;
    cout << "How many hours did you work on Wednesday:";
    cin >> c;
    cout << "How many hours did you work on Thursday:";
    cin >> d;
    cout << "How many hours did you work on Friday:";
    cin >> e;
    if (a > 8)
        a =(8 * 12.50) + (a % 8 * 18.75);
    else
        a = a * 12.50;
    if (b > 8)
        b =(8 * 12.50) + (b % 8 * 18.75);
    else
        b = b * 12.50;
    if (c > 8)
        c =(8 * 12.50) + (c % 8 * 18.75);
    else
        c = c * 12.50;
    if (d > 8)
        d =(8 * 12.50) + (d % 8 * 18.75);
    else
        d = d * 12.50;
    if (e > 8)
        e =(8 * 12.50) + (e % 8 * 18.75);
    else
        e = e * 12.50;
    sum = a + b + c + d + e;
    cout << "The total pay for the week is: $";
    cout << sum <<endl;
    return 0;
    
}
change the datatype of those from int to float.

int is for whole numbers, float is for floating-point numbers (numbers with decimals)
tried that, kept getting errors.

danielprobdos.cpp:30:29: error: invalid operands to binary expression
('float' and 'float')
a =(8 * 12.50) + (a % 8 * 18.75);
~ ^ ~
danielprobdos.cpp:34:29: error: invalid operands to binary expression
('float' and 'float')
b =(8 * 12.50) + (b % 8 * 18.75);
~ ^ ~
danielprobdos.cpp:38:29: error: invalid operands to binary expression
('float' and 'float')
c =(8 * 12.50) + (c % 8 * 18.75);
~ ^ ~
danielprobdos.cpp:42:29: error: invalid operands to binary expression
('float' and 'float')
d =(8 * 12.50) + (d % 8 * 18.75);
~ ^ ~
danielprobdos.cpp:46:29: error: invalid operands to binary expression
('float' and 'float')
e =(8 * 12.50) + (e % 8 * 18.75);
~ ^ ~
5 errors generated.
oh yeah, operator% is not available for floats...

use fmod instead: http://www.cplusplus.com/reference/cmath/fmod/

like this:
a =(8 * 12.50) + (fmod(a, 8) * 18.75);
Just found that out, haha. Thanks!
Topic archived. No new replies allowed.