A
={ Advocated }=
Hi there, im in need to use a loop, im not sure exactly how to do it :S
########################
/*
* File: Payroll.c
* Program to calculate the wage of a user
*/
#include <stdio.h>
int main(int argc, char* argv[])
{
double hoursWorked = 0.00;
double hourlyRate = 0.00;
double pay = 0.00;
double totalAmount = 0.00;
int fieldCount = 0;
printf("Please enter hours worked: ");
fflush(stdout);
fieldCount = scanf("%lf", &hoursWorked);
if (fieldCount != 1)
{
printf("Please enter a number value.\n");
return 0;
}
while( hoursWorked < 0.0 )
{
return 0;
printf("The hours worked are %.2f\n", hoursWorked);
}
printf("Please enter hourly rate: ");
fflush(stdout);
scanf("%lf", &hourlyRate);
printf("The hourly rate is %.2f\n", hourlyRate);
printf("The total amount is %.2f\n", hoursWorked * hourlyRate);
return 0;
}
###########################
I know that theres no need to use a while loop, but i wanted to try
something
Ive got it so that if they dont enter a value, i.e 5, 3 and enter say
hello, then it says "please enter a number value"
but in that case, i want it to then return to "please enter hours worked"
ive tried a few things, none seemed to work
I tried extending the if statement:
if (fieldCount != 1)
{
printf("Please enter a number value.\n");
return 0;
}
else
{
printf("Please enter hours worked: ");
}
but then that just messed up the code :S
Help or advise would be apreciated
########################
/*
* File: Payroll.c
* Program to calculate the wage of a user
*/
#include <stdio.h>
int main(int argc, char* argv[])
{
double hoursWorked = 0.00;
double hourlyRate = 0.00;
double pay = 0.00;
double totalAmount = 0.00;
int fieldCount = 0;
printf("Please enter hours worked: ");
fflush(stdout);
fieldCount = scanf("%lf", &hoursWorked);
if (fieldCount != 1)
{
printf("Please enter a number value.\n");
return 0;
}
while( hoursWorked < 0.0 )
{
return 0;
printf("The hours worked are %.2f\n", hoursWorked);
}
printf("Please enter hourly rate: ");
fflush(stdout);
scanf("%lf", &hourlyRate);
printf("The hourly rate is %.2f\n", hourlyRate);
printf("The total amount is %.2f\n", hoursWorked * hourlyRate);
return 0;
}
###########################
I know that theres no need to use a while loop, but i wanted to try
something
Ive got it so that if they dont enter a value, i.e 5, 3 and enter say
hello, then it says "please enter a number value"
but in that case, i want it to then return to "please enter hours worked"
ive tried a few things, none seemed to work
I tried extending the if statement:
if (fieldCount != 1)
{
printf("Please enter a number value.\n");
return 0;
}
else
{
printf("Please enter hours worked: ");
}
but then that just messed up the code :S
Help or advise would be apreciated