Click here to Skip to main content
       

C / C++ / MFC

 
Questionneed code to check if the value is numeric in C PinmemberMikerush74-Oct-12 7:49 
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 ?  
 
int main()
{
     
   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)
            return hours;
            else
            printf ("You entered invalid data, please enter number of hours \n");
           
           
      if (isdigit(payrate) !=0)
            return payrate;
            else
            printf ("You entered invalid data, please enter payrate \n");
              
      if (hours==0 || payrate==0)
               {
               printf ("Good Bye. \n\n");
               system("PAUSE");
               return 0;
               }
                          
   double grosspay;
   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);
AnswerRe: need code to check if the value is numeric in C PinmvpRichard MacCutchan4-Oct-12 8:22 
GeneralRe: need code to check if the value is numeric in C PinmemberMikerush74-Oct-12 8:50 
GeneralRe: need code to check if the value is numeric in C PinmvpRichard MacCutchan4-Oct-12 8:53 
AnswerRe: need code to check if the value is numeric in C PinmvpCPallini4-Oct-12 10:48 
QuestionRe: need code to check if the value is numeric in C PinmemberDavidCrow4-Oct-12 10:55 
AnswerRe: need code to check if the value is numeric in C PinmvpRichard MacCutchan4-Oct-12 22:37 
GeneralRe: need code to check if the value is numeric in C PinmemberMikerush75-Oct-12 9:30 
AnswerRe: need code to check if the value is numeric in C PinmemberC Mahesh8-Oct-12 23:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 27 Nov 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid