Home Forums C Programming C program timeout

Viewing 1 reply thread
  • Author
    • #2237

      Here is the program I have at the moment

      int main (void) //Main program function

      char *stores[3] = {"Del Mar", "Encinitas", "La Jolla"};
      float taxPercent[3]={7.25, 7.5, 7.75}; // Tax variable for all three stores
      float price; //float variable for the price

      do {
      printf("ttKudler Fine Foods Tax Calculatornn"); // prints header
      printf("Please enter the amount of your purchase: ");
      scanf("%f", &price);

      if (0.0 > price) {
      printf("Purchase amount must be positiven");
      } while(price < 0.0);

      float taxTotal[3] = {price * (taxPercent[0]/100), price * (taxPercent[1]/100), price * (taxPercent[2]/100)}; //calculates the total for each store

      printf("nThe tax for the %s store at %.2f%% is %.2f", stores[0], taxPercent[0], taxTotal[0]); //prints tax information for Del Mar
      printf("nThe tax for the %s store at %.2f%% is %.2f", stores[1], taxPercent[1], taxTotal[1]); //prints tax information for Encinitas
      printf("nThe tax for the %s store at %.2f%% is %.2f", stores[2], taxPercent[2], taxTotal[2]); //prints tax information for La Jolla

      getch(); // waits for user to press a key

      return 0; // return of int main()

      } // end main

      I want to add a timeout function on the if statement in blue and then clear the screen with system(“cls”); Any help on how to create the timeout function?

      I am using Dev C++ compiler and what I am trying to do is asking a user to enter a purchase amount, if it is negative I am giving them a message it must be positive then after about 10 second clear the screen so they can reenter a proper purchase price.

    • #3626

      You use can sleep function for prompting to require amount of time.

      In condition you add the sleep(10).

      It will wait for 10 seconds, then do the require stuffs

Viewing 1 reply thread
  • The forum ‘C Programming’ is closed to new topics and replies.