Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Registered User (http://www.go4expert.com/forums/registered-user-t2959/)

kuchma2000 12Feb2007 04:30

Registered User
 
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]);
  }
}


shabbir 12Feb2007 09:12

Re: Registered User
 
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.

DaWei 12Feb2007 19:38

Re: Registered User
 
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.


All times are GMT +5.5. The time now is 05:56.