Home › Forums › C Programming › C program timeout
- This topic has 1 reply, 2 voices, and was last updated 14 years, 10 months ago by Chandra3993.
Viewing 1 reply thread
- AuthorPosts
- February 2, 2010 at 8:05 am #2237PreciouLononParticipant
Here is the program I have at the moment
123456789101112131415161718192021222324252627282930<br />int main (void) //Main program function<br />{<br /><br />char *stores[3] = {"Del Mar", "Encinitas", "La Jolla"};<br />float taxPercent[3]={7.25, 7.5, 7.75}; // Tax variable for all three stores<br />float price; //float variable for the price<br /><br />do {<br />printf("ttKudler Fine Foods Tax Calculatornn"); // prints header<br />printf("Please enter the amount of your purchase: ");<br />scanf("%f", &price);<br /><br /><span style="color:#0000FF"> if (0.0 > price) {<br />printf("Purchase amount must be positiven");<br />}<br />} while(price < 0.0);</span><br /><br />float taxTotal[3] = {price * (taxPercent[0]/100), price * (taxPercent[1]/100), price * (taxPercent[2]/100)}; //calculates the total for each store<br /><br />printf("nThe tax for the %s store at %.2f%% is %.2f", stores[0], taxPercent[0], taxTotal[0]); //prints tax information for Del Mar<br />printf("nThe tax for the %s store at %.2f%% is %.2f", stores[1], taxPercent[1], taxTotal[1]); //prints tax information for Encinitas<br />printf("nThe tax for the %s store at %.2f%% is %.2f", stores[2], taxPercent[2], taxTotal[2]); //prints tax information for La Jolla<br /><br />getch(); // waits for user to press a key<br /><br />return 0; // return of int main()<br /><br />} // end main<br />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.
- February 23, 2010 at 6:12 am #3626Chandra3993Participant
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
- AuthorPosts
Viewing 1 reply thread
- The forum ‘C Programming’ is closed to new topics and replies.