Thread: Nested loop timer

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    3

    Nested loop timer

    So I have to build a program that is timer in the format of h:m:s. It's based off a martian time scale. This is what I have, but the program will do some wierd thing at the beggning where it like shows the minutes, but then loses them and just counts the seconds over and over. Plus i need to put in a reminder at certain times, and thats not showing up.
    Code:
    #include <stdio.h>
    
    #define HOURS 20
    #define MINS 12
    #define SECS 15
    
    int main() {
    
    int choice=0;
    int fchoice;
    int hours,mins, secs;
    int th, tm, ts;
    int done=0;
    
    hours=0;
    mins=0;
    secs=0;
    
    while (choice != 3) {
    //Choice
      printf("Choose one of the following menu options\n");
      printf("1: set time\n");
      printf("2: start timer\n");
      printf("3: quit\n");
      scanf("%d", &choice);
     
    //Converstions
     // Execute option 1.
      if (choice == 1) {
    		printf("Enter in the time.\n");
    		scanf("%d:%d:%d", &hours, &mins, &secs);
      
      	
      }
      // Execute option 2.
      else if (choice == 2) {
    
      printf("How long would you like me to count?\n");
      scanf("%d:%d:%d", &th, &tm, &ts);
      
      hours+=HOURS;
      mins+=MINS;
      secs+=SECS;
      
      while (done!=1){
      for (hours=hours-HOURS;((hours<HOURS)&&(done!=1));hours++)
      	for (mins=mins-MINS;((mins<MINS)&&(done!=1)); mins++)
    		for (secs=secs-SECS;((secs<SECS)&&(done!=1)); secs++)
    		{
    			printf("current time  >  %d:%d:%d\n", hours,mins,secs);
    				printf("current timer  >  %d:%d:%d\n", th,tm,ts);
    			
    			if ((hours=4)&&(mins=0)&&(secs=0)){
    				printf("Have you had your breakfast?\n");
    				printf("1: Yes\n");
    				printf("0: No\n");
    				scanf("%d", &fchoice);
    				}
    				
    				if ((th==0)&&(tm==0)&&(ts==0)){
    				done=1;
    				}
    				ts--;
    					if (ts==-1){
    						ts=SECS-1;
    				
    						if(tm==-1){
    							tm=MINS-1;
    								if(th==-1){
    									th=HOURS-1;}
    								else 
    									th--;
    								}
    						else
    							tm--;
    						 }
    				 }
    		 }
    		
    			hours=0;
    			mins=0;
    			secs=0;
      }
      
      else if (choice == 3) {
      
      printf("Thankyou.\n");
      break;
      }
      
      else
      		printf("invalid answer, try again.\n");
    }
      return 0;
    }

  2. #2
    Registered User
    Join Date
    Mar 2006
    Posts
    3
    Saw Cgurl has the same problem, so looking at that to see if i see anything

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  2. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 05:01 PM
  3. nested loop, simple but i'm missing it
    By big_brother in forum C Programming
    Replies: 19
    Last Post: 10-23-2006, 10:21 PM
  4. Nested for loop...search & display a list within a list
    By chadsxe in forum C++ Programming
    Replies: 13
    Last Post: 07-20-2005, 01:34 PM
  5. output from nested while loop
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 08-22-2002, 09:30 AM