I am student, taking C programming now.
I have assignment to write function to check if inputed data is numbers. if not - it should write that, and ask to enter number again.
I wrote code, to write error message, but dont know how to make program to work on next input.. should I call the Main function again ?
double hours; //hours worked in a week
double payrate; // hourly salary
double grosspay; //total weekly payment
int k; //number of values read
printf ("Enter number of hours, and hourly pay (or press 0 to exit) \n");
while ((k = scanf ("%lf%lf", &hours, &payrate))==2)
if (isdigit(hours) !=0)
printf ("You entered invalid data, please enter number of hours \n");
scanf ("%lf, &hours)
if (isdigit(payrate) !=0)
printf ("You entered invalid data, please enter payrate \n");
scanf ("%lf, &payrate)
if (hours==0 || payrate==0)
printf ("Good Bye. \n\n");
grosspay = calculateGrossPay(hours, payrate);
printf ("Hours worked: %.2f\n", hours);
printf ("Hourly Rate: %.2f\n\n", payrate);
printf ("Your weekly payment is: $ %.2f \n\n\n", grosspay);
I checked the page "How do i get a number from the user", but still did not understand how to fix it.. Any advice would be appreciated.
Thank you !