Change order of how input is collected

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • haidernumero
    New Member
    • Feb 2010
    • 2

    Change order of how input is collected

    supposed, user should enter 5 number first and then they will select whether to find the smallest number, largest, sum and average. but then. my program here, do the selection first then enter five number. can anyone help me how to repair it. coz i'm blurred.

    Code:
    #include <stdio.h>
    
    int menu(void);        //list of function listed in this program
    void smallestNo(void);
    void largestNo(void);
    void sum(void);
    void average(void);
    
    
    int main()
    {
      int selection;
    
      selection=menu();
    
      switch(selection)
      {
    	 case 1:smallestNo();
    			  break;
    	 case 2:largestNo();
    			  break;
    	 case 3:sum();
    			  break;
    	 case 4:average();
    			  break;
    	 case 5:printf("EXIT....");
    			  break;
    	 default:printf("\nYou have entered INVALID selection!\nPlease try again!");
    
      }//end switch
    
      return 0;
    }//end main
    
    
    int menu(void)
    {
    	  int select;
    
    	  printf("\t\t\t*************************************");
    	  printf("\n\t\t\t* WELCOME TO MY CALCULATING PROGRAM *");
    	  printf("\n\t\t\t*************************************");
    	  printf("\n\t\t\t*                                   *");
    	  printf("\n\t\t\t*\t1. SMALLEST                 *");
    	  printf("\n\t\t\t*\t2. LARGEST                  *");
    	  printf("\n\t\t\t*\t3. SUM                      *");
    	  printf("\n\t\t\t*\t4. AVERAGE                  *");
    	  printf("\n\t\t\t*\t5. Exit                     *");
    	  printf("\n\t\t\t*************************************");
    
    	  printf("\n\n\t\tMAKE YOUR SELECTION==>");
    	  scanf("%d",select);
    
    
      return select;
    }//end function menu
    
      void smallestNo(void)//function smallest.
      {
    	int num;
    	int smallest;
    	int bilNum=1;
    
    	printf("\n\tEnter 5 numbers ");
    	printf("\n\n\tNumber %d : \n",bilNum);
    	scanf("%d",&num);
    
    	smallest=num;
    	while (bilNum<5)
    	{
    		if(num<smallest)
    		smallest=num;
    		bilNum=bilNum+1;
    		printf("\tNumber %d : ",bilNum);
    		scanf("%d",&num);
    	}//end while
    
    	printf("\n\tSmallest number: %d",smallest);
    	return;
      }//end function Smallest.
    
    
      void largestNo(void)
      {
    	int num;
    	int largest;
    	int bilNum=1;
    
    	printf("\n\tEnter five numbers:\n\n");
    
    		num=0;
    		largest=0;
    	while (bilNum<6)
    	{
    		printf("\tNumber %d : ",bilNum);
    		scanf("%d",&num);
    
    		if(num>largest)
    		largest=num;
    
    		bilNum=bilNum+1;
    
    	}//end while
    	printf("\n\tLargest number: %d",largest);
    	return;
    
      }//end function Largest.
    
    
    
      void sum(void)
      {
    	int num,sum,bilNum;
    		bilNum=1;
    		sum=0;
    	printf("\n\tEnter five numbers:\n\n");
    
    	  while (bilNum<6)
    		{
    		printf("\tNumber %d : ",bilNum);
    		scanf("%d",&num);
    
    		sum=sum+num;
    
    		bilNum=bilNum+1;
    
    		}//end while
    	printf("\n\tSum of the numbers: %d",sum);
    	return;
      }//end function Sum
    
      void average(void)
      {
    	int num,bilNum;
    	float sum,average;
    
    		bilNum=1;
    		sum=0;
    		average=0;
    		printf("\n\tEnter five numbers:\n\n");
    
    	  while (bilNum<6)
    	  {
    		printf("\tNumber %d : ",bilNum);
    		scanf("%d",&num);
    
    		sum=sum+num;
    		average=sum/bilNum;
    
    		bilNum=bilNum+1;
    
    		}//end while
    	printf("\n\tAverage of the numbers: %.2f",average);
    
    	return;
      }//end function Average
    
      void Exit(void)
      {
    	 printf("\n\tYou are now exit from the program..thank you");
    
    	 return; //end function exit
      }
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Exactly what are you trying to fix?

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      weaknessforcats :
      The posted program first has the user specify the type of operation they wish to perform; and then has them enter the numbers to be acted on. Sounds like the OP is asking for help changing the program to make those requests in the opposite order.

      haidernumero:
      Where did you obtain the program that you posted?

      Comment

      • haidernumero
        New Member
        • Feb 2010
        • 2

        #4
        weaknessforcats :
        thing is i want user to enter their 5 number first and then ask them to choose to find smallest,larges t sum or average. program i wrote up there actually ask the user to select between smallest, largest etc. first then ask them to enter the number.

        donbock:
        that i do by myself. why?

        Comment

        Working...