Thread: Any assistance would be greatly appreciated

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    32

    Any assistance would be greatly appreciated

    Code:
    //Jonathan Barnwell
    //COP 3223 Section 1
    //Program III
    //02/23/06
    
    #include <stdio.h>
    
    #define HRS_DAY 20 //define hours per day
    #define MINS_HR 12 //define minutes per hour
    #define SECS_MIN 15 //define seconds per minute
    
    int main(void)	{
    	
    	int menu_choice; //Gather user menu choice
    	int h = 0, m = 0, s = 0; //current time
    	int hT, mT, sT; //count time
    	
    	do	{
            //heres my menu
    	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", &menu_choice);
    
    		if (menu_choice == 1)	{
    			printf("What is the current time?\n");
    			scanf("%d:%d:%d", &h, &m, &s);
    		}
    		else if (menu_choice == 2)	{
    			printf("How long would you like me to count?\n");
    			scanf("%d:%d:%d", &hT, &mT, &sT);
                            //I am supposed to take every second and print it until that interval expires
    		}
    		else if (menu_choice == 3)	{
    			printf("Thank you.\n");
    		}
    		else	{
    			printf("Sorry, that is not a valid menu choice.\n");	
    		}
    			
    	}	while (menu_choice != 3);
    
    	return 0;
    }
    The whole event takes place on mars, so you can see the different time intervals for minutes, hours and days respectevely at the top.

    I'm supposed to create a menu for the user, (set time/start timer/quit)

    as you can see, most of that is already input.

    next i am to take the current time and print in seconds until the interval provided expires. (for example using EARTH, if its 2:00:00 and he wants me to count for an hour i'm supposed to print every second until three a clock.)

    i hope that makes sense

    i don't know how to continue from here

    please advise

    Michael

    PS theres more to it, i'm just trying to understand it step by step
    Last edited by iiwhitexb0iii; 02-23-2006 at 07:53 PM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Looks like you need a loop. You'll need to think about how a clock works, and duplicate that process. Surely you've got some idea how a clock works. Let's see you give it a shot.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    32
    convert total time in interval to seconds

    add seconds to original time incrimenting minutes and hours when necessary but how?

    i'm not asking for a complete solution, just something to point me in a better direction compared to what i have now.

  4. #4
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    What happens on a clock when it reaches 59 seconds and needs to increment? Quite obvious, really.

  5. #5
    Registered User
    Join Date
    Feb 2006
    Posts
    32
    i understand the logic behind what is asked of me, the only problem is the mental leap of being able to explain it to the computer.

    this is my first year in C so i'm still learning

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Since you're using #defines
    Code:
    #define HRS_DAY 20 //define hours per day
    #define MINS_HR 12 //define minutes per hour
    #define SECS_MIN 15 //define seconds per minute
    why not change them to "Earth" for development and initial debugging, and then later change them back?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  7. #7
    Registered User
    Join Date
    Feb 2006
    Posts
    32
    i like where your heads at

  8. #8
    Registered User cbastard's Avatar
    Join Date
    Jul 2005
    Location
    India
    Posts
    167
    Code:
    total = (hT * MINS_HR * SECS_MIN) + (mT * SECS_MIN) + (sT);
    printf("HERE WE GO!\n");
    while (total > 0){
    	printf("%d:%d:%d", h, m, s);
    	if (s == SECS_MIN)	{
    			m = m +1;
    			s = 0;
    			}
    	if (m == MINS_HR)	{
    			h = h + 1;
    			m = 0;
    			}
    	if (h == HRS_DAY)	{
    			h =0;
    			}
    	total = total - 1;
    	}
    You will keep on printing same values of h,m,s.
    You have to increment s in while loop.otherwise your If statements will not work the way you want it.
    Long time no C. I need to learn the language again.
    Help a man when he is in trouble and he will remember you when he is in trouble again.
    You learn in life when you lose.
    Complex problems have simple, easy to understand wrong answers.
    "A ship in the harbour is safe, but that's not what ships are built
    for"

  9. #9
    Registered User
    Join Date
    Feb 2006
    Posts
    32
    i appreciate your reply, everything seems to be working now except rolling over to the next day..which i will fix

  10. #10
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Gotta increment your seconds in that, Tonto. Also, don't forget, that code's "second" is the time it takes to loop. In otherwords, rediculously fast. You'll need to use a sleep function if you want proper speed.

    Code:
    printf("%d:%d:%d\n", h, m, s);
    s++;
    if (s == 60)	{
    Sent from my iPadŽ

  11. #11
    Registered User
    Join Date
    Feb 2006
    Posts
    32
    Code:
    else if (menu_choice == 2)	{ //begin menu choice 2
    			printf("How long would you like me to count?\n");
    			scanf("%d:%d:%d", &hT, &mT, &sT);
    			total = (hT * MINS_HR * SECS_MIN) + (mT * SECS_MIN) + (sT);
    			Bt = total - breakfast;
    			Lt = total - lunch;
    			Dt = total - dinner;			
    			printf("HERE WE GO!\n");
    				while (total > 0)	{
    					printf("%d:%d:%d", h, m, s);
    					s = s + 1;
    						if (s == SECS_MIN)	{
    							m = m +1;
    							s = 0;
    						}
    						if (m == MINS_HR)	{
    							h = h + 1;
    							m = 0;
    						}
    						if (h == HRS_DAY)	{
    							h = 0;
    						}
    					total = total - 1;
    					printf("\n");
    				}
    		} //end menu choice 2
    User inputs start time and amount of time wanted to count for. I'm required to remind the user to eat breakfast between 4:00:00 and 5:00:00

    i already have a random number for the amount of seconds in the breakfast break interval, Bt.

    now i just need to remind the user after the specified seconds...please help me

  12. #12
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Code:
    while (total > 0) {
    	printf("%d:%d:%d", h, m, s);
    	s = s + 1;
    	if (s == SECS_MIN) {
    		m = m + 1;
    		s = 0;
    		}
    	if (m == MINS_HR) {
    		h = h + 1;
    		m = 0;
    		}
    	if (h == HRS_DAY)
    		h = 0;
    	total = total - 1;
            if (total == Bt)
    		printf("\nIt's breakfast time!");
    	printf("\n");
    }
    Sent from my iPadŽ

  13. #13
    Registered User
    Join Date
    Feb 2006
    Posts
    32
    sadly nothing

  14. #14
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Well I can only assume with the variable breakfast contains. So I can't write you exact statement. By the way, when people write this code, it's not for you to copy and paste, it's for you to learn from.
    Sent from my iPadŽ

  15. #15
    Registered User
    Join Date
    Feb 2006
    Posts
    32
    my fault i mis-understood your intentions, i will continue working at it and i appreciate your help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assistance greatly needed to do LCD Display
    By HELPMEPLEASE!!! in forum C Programming
    Replies: 6
    Last Post: 03-28-2009, 05:07 PM
  2. Noobie question, all help greatly appreciated!
    By axehero in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2007, 09:47 PM
  3. Replies: 2
    Last Post: 05-10-2006, 10:43 PM
  4. Simple question. Help will be appreciated.
    By wickedclownz in forum C++ Programming
    Replies: 2
    Last Post: 06-19-2003, 02:18 AM
  5. Your help would be greatly appreciated
    By Sway2 in forum C++ Programming
    Replies: 3
    Last Post: 12-03-2002, 07:55 AM