Do not work (compiling no errors)

Hi, can anyone talk to me why code do not work good?
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>
using namespace std;
double Data (double &a,double &b)
{
    int temp;
    do
    {
        cout << "TYpe time (HH.MM)"<< endl;
        cin >> a;
        temp=int (a);
    }while ((a-temp>0.59)||(a>23.59));
    cout << "Call long (minutes): "<< endl;
    cin >> b;
    return 0.00;
}
int main ()
{
    double time, minutes, charge(0);
    Data (time,minutes);
    double tend=time;
    int t;
    while (minutes>0)
    {
        t=static_cast<int>(tend);
        if (tend-t==0.59)
        {
            if(t==23)
            {tend=00.00;}
            else
            {tend-=0.59;    tend+=1.00;}
        }
        else 
        {tend+=0.01;        }
        
        if (tend>0.00&&tend<7.00) 
        charge+=0.12;
        if(tend>7.00&&tend<19.00) 
        charge+=0.55;
        if(tend>19.01) 
        charge+=0.35;
        
        minutes--;        
    }
    cout << "Calling from: "<<time<<" to "<< tend <<" cost "<< charge<<endl; 
    cout << "\n";
    system ("pause");
}
Last edited on
What does it do that you don't want it to do?
Program should get time when call began and how long call was been and output time when call was finished and cost of call.
When I input 23.59(start time)
and input2: 3(call long in minutes)
tend must be 0.02
but its int this case tend output is 23.62

I do not understand why output 23.62 I write code in while but its not affective?
Can anyone tell me why and how fix this problem?
if (tend-t==0.59)

You're comparing a floating point number. As a general rule of thumb, that doesn't work.

http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
thank you so much it helps a lot
Topic archived. No new replies allowed.