Registered User

Discussion in 'C' started by kuchma2000, Feb 11, 2007.

  1. kuchma2000

    kuchma2000 New Member

    Joined:
    Feb 11, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi everyone.
    I have a C program (see code below) which I need to urgrade, but I'm new to C programming and after hour of trying to do this I finally gave up and decided to ask some one for HELP.
    Here is what I need to do:

    a. Extract the temps for the City #1 and store in a one dimensional array, display the array.
    b. Sort the one dimensional array of City #1 temps using a selection sort and display the sorted array
    c. Extract the temps recorded from all Cities as 3rd entry and store in a one dimensional array, display the array
    d. Sort the one dimensional array of temps taken as 3rd entry using a bubble sort and display the sorted array

    Can anyone help me with this.
    Many Thanks.
    Andrew

    Here is the CODE:

    Code:
    #include <stdio.h>
    #include <ctype.h>
    #include <stdlib.h>
    
    #define CITY  4
    #define TEMPS  4
    
    int temp[CITY][TEMPS];
    
    void enter_temp(void);
    int get_temp(int num);
    void disp_temp(int g[][TEMPS]);
    
    
    void main()
    {
      char ch, str[80];
    
      for( ; ; ) {
        do {
          printf("(E)nter TEMPs\n");
          printf("(R)eport TEMPs\n");
          printf("(Q)uit\n");
          gets(str);
          ch = toupper(*str);
        } while(ch!='E' && ch!='R' && ch!='Q' && ch!='S');
    
        switch(ch) {
          case 'E':
            enter_temp();
            break;
          case 'R':
            disp_temp(temp);
            break;
          case 'Q':
            exit(0);
        }
      }
    }
      
    /* Enter the temps. */
    
    void enter_temp(void)
    {
      int t, i;
        printf ("City #1 - Diblin, City #2 - Cork, \n");
        printf ("City #3 - Galway, City #4 - Monaghan\n");
      for(t=0; t<CITY; t++) {
        printf("City # %d:\n", t+1);
        for(i=0; i<TEMPS; ++i)
          temp[t][i] = get_temp(i);
      }
    }
    
    /* Read a TEMPs. */
    
    int get_temp(int num)
    {
      char s[80];
    
      printf ("TEMP #1 - 6am, TEMP #2 - 12pm, \n");
        printf ("TEMP #3 - 6pm, TEMP#4 - 12am\n");
      printf("Enter TEMP # %d:\n", num+1);
      gets(s);
      return(atoi(s));
    }
    
    /* Display temps. */
    
    
    void disp_temp(int g[][TEMPS])
    {
      int t, i;
    
      for(t=0; t<CITY; ++t) {
        printf("City # %d:\n", t+1);
        for(i=0; i<TEMPS; ++i)
          printf("TEMP #%d is %d\n", i+1, g[t][i]);
      }
    }
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,376
    Likes Received:
    388
    Trophy Points:
    83
    If you are looking for something like paid services then you should look for MarketPlace section in cfanatic.com or if you are looking for some help frame your question in such a manner that we know where the problem area is and not like here is the code to find the probs.
     
  3. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    I might add that "Registered User" does not describe the problem you have and the solution you are seeking. It certainly isn't a worthwhile search term. You didn't read "Before you make a query"? Why ever not? Inquiring minds want to know.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice