Thread: Can anyone help me?!?!?!

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    2

    Unhappy Can anyone help me?!?!?!

    I need help finishing a program. the program is supposed to be as follows:

    Description
    This program will allow the user to enter and store the temperatures for each day of the month. The user is then presented with a menu like this:

    [1] Print all temperatures.
    [2] Print all temperatures sorted largest to smallest.
    [3] Print the average monthly temperature.
    [4] Search for a particular temperature.
    [5] Quit.

    The menu will continuously loop until the user enters quit.

    Requirements:

    The user is only asked to enter the entire month’s temperatures once.
    The program must work for any number of days in the month up to 31(you’ll need to keep a counter inside the input function and then return it to main)
    If the user sorts the temperatures this must NOT affect the original input( You’ll need a temporary array to store the temperatures for sorting).
    The search routine prints ALL the days on which a particular temperature occurred.
    You must use the complete bubble sort algorithm for sorting.
    Your program must report a invalid entry if any number other than 1-5 is entered at the menu.
    You must use a separate function for each menu item and for array input ( given below)
    You must use an integer array to store temperatures.
    You will need a temporary array( local to print_sorted() ) to store the temperatures for sorting).
    The average temperature displayed must be a float.
    The temperature array must be declared in main and passed between functions.
    The size of the array must be 31 and must be ‘declared’ in a #define.
    You may not use any global variables.

    Functions:
    You will need at least 5 functions but you may have more. The 5 mandatory functions are:

    Int input_temperature(int[], int); // return the number of temperatures entered
    void print_all(int[], int);
    void print_sorted(int[], int);
    void print_average(int[], int);
    void search(int[], int);

    Each function must be passed at least the original temperature array and the functional size of the array. You may pass in more information if you find it useful.

    This is what i have done so far:
    #include <stdio.h>
    #define SIZE 31
    int input_temperature(int [], int);

    int main()
    {

    int temperature[SIZE] = {0};
    int counter, days;

    days = input_temperature(temperature, days);

    /* return 0; */

    }


    /* void print_sorted( int [], int); */
    /* { */
    /* int pass, j, hold; */

    /* for ( pass = 1; pass <= SIZE -1; pass++ ) */

    /* for ( j = 0; j <= SIZE -2; j++ ) */

    /* if ( a[ j ] > a[ j + 1 ] ) { */
    /* hold = a [ j ]; */
    /* a [ j ] = a[ j + 1 ]; */
    /* a [ j + 1 ] = hold; */
    /* } */
    /* } */


    int input_temperature(int temp[], int days){

    printf("Enter the temperatures for the entire month\n ");
    char decision;
    int counter = 0, input;

    while ( counter <= SIZE )
    {

    days = counter;

    if ( counter >= 5 )
    {

    printf( "Do you need to input another day? (Y/N)\n ");
    /*scanf( "%c", &decision );*/

    if ( decision == 'Y' )
    {

    printf( "Enter the next temperature:\n");
    scanf ("%d", &input);
    temp[counter] = input;
    counter++;

    }

    else

    counter = SIZE + 1;

    }

    else
    {
    scanf( "%d", &input);
    temp[counter] = input;
    counter++;
    }

    }

    return days;

    }

  2. #2
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Menu:
    Code:
    #include <stdio.h>
    #include <conio.h>
    
    int display_menu();
    int menu();
    
    int display_menu()
    {
    	clrscr();
    	printf("1 = Option 1\n");
    	printf("2 = Option 2\n");
    	printf("3 = Option 3\n");
    	printf("4 = Option 4\n");
    	printf("5 = Quit\n\n");
    	return 0;
    }
    
    int menu()
    {
    	char choice;
    	while(display_menu() == 0)
    	{
    		choice=getch();
    		switch(choice)
    		{
    			case '1':
    			printf("Choice 1 was chosen.\n\nPress a key...");
    			getch();
    			break;
    
    			case '2':
    			printf("Choice 2 was chosen.\n\nPress a key...");
    			getch();
    			break;
    
    			case '3':
    			printf("Choice 3 was chosen.\n\nPress a key...");
    			getch();
    			break;
    
    			case '4':
    			printf("Choice 4 was chosen.\n\nPress a key...");
    			getch();
    			break;
    
    			case '5':
    			return 0;
    
    			default:
    			break;
    		}
    	}
    return 0;
    }
    
    int main()
    {
    	menu();
    	return 0;
    }
    > The menu will continuously loop until the user enters quit.
    This one does just that. I wrote it in a few minutes with GCC on Win98SE and tested it a few times. It loops on default, it loops after a choice, and it quits immediately. It should be fine.

    > I need help finishing a program.
    There's a little to keep the ball rolling.

    P.S. Use code tags and don't make homework posts seem so obvious.
    The world is waiting. I must leave you now.

Popular pages Recent additions subscribe to a feed