# C time dont work :s

Hallo,
im making a program it should do the following
first it ask for you start hour you begin to work and then how long the pauze 01 was and the same for the lunch pauze and pauze02.
but its not working as i expected for example when i type in strat hour 12.00 and 00.1 pauze one and 00.1 pauze02 and 00.1 lunch pauze and the stop time is 15.00, it gives mee 2.40 which is wrong it shuld be just two hours right ?

``````#include <stdio.h>
#include <conio.h>
int main (void)
{
float antwoord=0;
float tafel[10]={};

printf("Geef u start tijd");
scanf("%f",&antwoord);
getchar();
tafel[0]=antwoord;

printf("How long was pauze01? ");
scanf("%f",&antwoord);
tafel[1]=antwoord;
getchar();

printf("How long was pauze02? ");
scanf("%f",&antwoord);
tafel[2]=antwoord;
getchar();

printf("How long was lunch pauze? ");
scanf("%f",&antwoord);
tafel[3]=antwoord;
getchar();

if ( tafel[1] || tafel[2] < 00.15 )
{
tafel[1]=00.15;
tafel[3]=00.15;
}

if (tafel[3] < 00.30)
tafel[2]=00.30;

printf("Wanneer bent u gestopt? ");
scanf("%f",&antwoord);
getchar();
tafel[4]=antwoord;

printf("U heefdt %.2f uur gepresteerd", (tafel[4]-tafel[0]) -(tafel[2]+tafel[1]+tafel[3]) );

getchar();

}
``````
ALaRiva

There are a few mistakes in the code and logic, but I'm a little short on time.

A few hints, and maybe someone else can finish this off for you.

When you store tafel[1] and [2] as 0.15, YOU are expecting that to mean 15 minutes, but since you are using numeric values, it does not equal the same. 15 minutes is .25 of 1 whole hour.

To get the value as a percent of the hour, then you would do this (tafel[1] / .60). So if tafel[1] was .15, you would get .25, which is what you are really looking for.

Same with the .30 - if you do tafel[3]/.60, and tafel[3] is .30, then you would get .50, which is the value you are really after.

So with that said, the code would be like this...

I changed your IF statement that has the || in it.

Also, review these if statements:
if ( tafel[1] < 00.15 || tafel[2] < 00.15 )
{
tafel[1]=00.15;
tafel[3]=00.15;
}

if (tafel[3] < 00.30)
tafel[2]=00.30;

I could be misunderstanding, but I think you should have them as ...

if ( tafel[1] < 00.15 || tafel[2] < 00.15 )
{
tafel[1]=00.15;
tafel[2]=00.15;
}

if (tafel[3] < 00.30)
tafel[3]=00.30;

My understanding is that you were trying to round up, but you have the assignments wrong.

HTH

- Anthony
``````#include <stdio.h>
#include <conio.h>
int main (void)
{
float antwoord=0;
float tafel[10]={};

printf("Geef u start tijd");
scanf("%f",&antwoord);
getchar();
tafel[0]=antwoord;

printf("How long was pauze01? ");
scanf("%f",&antwoord);
tafel[1]=antwoord;
getchar();

printf("How long was pauze02? ");
scanf("%f",&antwoord);
tafel[2]=antwoord;
getchar();

printf("How long was lunch pauze? ");
scanf("%f",&antwoord);
tafel[3]=antwoord;
getchar();

if ( tafel[1] < 00.15 || tafel[2] < 00.15 )
{
tafel[1]=00.15;
tafel[3]=00.15;
}

if (tafel[3] < 00.30)
tafel[2]=00.30;

printf("Wanneer bent u gestopt? ");
scanf("%f",&antwoord);
getchar();
tafel[4]=antwoord;

//prepare values for hours
tafel[1] = tafel[1]/.60
tafel[2] = tafel[2]/.60
tafel[3] = tafel[3]/.60

printf("U heefdt %.2f uur gepresteerd", (tafel[4]-tafel[0]) -(tafel[2]+tafel[1]+tafel[3]) );

getchar();
``````
MURUGESAN N

membership
Create an account to see this answer
Signing up is free. No credit card required.