# 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();

}
``````
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
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();
``````
Shell_script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX C C++ CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NT started powershellCommented:
Updated code for removing compilation errors and warnings.

``````#include <stdio.h>
#include <conio.h>  /* This is used in Turbo C/C++ */
int main (void)
{
float antwoord = 0 ;
float tafel[10] = { 0.0 } ; /* Initialize the all the elements in this array as 0.0 */
clrscr() ; /* This is used in Turbo C/C++ */
printf("Give your start time: ") ;
scanf("%f",&antwoord) ;
tafel[0] = antwoord ;
printf("How long was the first break?: ") ;
scanf("%f",&antwoord) ;
tafel[1] = antwoord ;
printf("How long was the second break?: ") ;
scanf("%f",&antwoord) ;
tafel[2] = antwoord ;
printf("How long was for lunch break?: ") ;
scanf("%f",&antwoord) ;
tafel[3] = antwoord ;
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("Give your end time?: ") ;
scanf("%f",&antwoord) ;
tafel[4] = antwoord ;
//prepare values for hours
tafel[1] = tafel[1]/.60 ;
tafel[2] = tafel[2]/.60 ;
tafel[3] = tafel[3]/.60 ;
printf("Your spreadsheet %.2f well enough\n", (tafel[4]-tafel[0]) -(tafel[2]+tafel[1]+tafel[3]) ) ;
printf("Press any key to quit\n") ;
getch() ;
return 0 ;
}
``````

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.