473,385 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Change order of how input is collected

haidernumero
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.

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. int menu(void);        //list of function listed in this program
  4. void smallestNo(void);
  5. void largestNo(void);
  6. void sum(void);
  7. void average(void);
  8.  
  9.  
  10. int main()
  11. {
  12.   int selection;
  13.  
  14.   selection=menu();
  15.  
  16.   switch(selection)
  17.   {
  18.      case 1:smallestNo();
  19.               break;
  20.      case 2:largestNo();
  21.               break;
  22.      case 3:sum();
  23.               break;
  24.      case 4:average();
  25.               break;
  26.      case 5:printf("EXIT....");
  27.               break;
  28.      default:printf("\nYou have entered INVALID selection!\nPlease try again!");
  29.  
  30.   }//end switch
  31.  
  32.   return 0;
  33. }//end main
  34.  
  35.  
  36. int menu(void)
  37. {
  38.       int select;
  39.  
  40.       printf("\t\t\t*************************************");
  41.       printf("\n\t\t\t* WELCOME TO MY CALCULATING PROGRAM *");
  42.       printf("\n\t\t\t*************************************");
  43.       printf("\n\t\t\t*                                   *");
  44.       printf("\n\t\t\t*\t1. SMALLEST                 *");
  45.       printf("\n\t\t\t*\t2. LARGEST                  *");
  46.       printf("\n\t\t\t*\t3. SUM                      *");
  47.       printf("\n\t\t\t*\t4. AVERAGE                  *");
  48.       printf("\n\t\t\t*\t5. Exit                     *");
  49.       printf("\n\t\t\t*************************************");
  50.  
  51.       printf("\n\n\t\tMAKE YOUR SELECTION==>");
  52.       scanf("%d",select);
  53.  
  54.  
  55.   return select;
  56. }//end function menu
  57.  
  58.   void smallestNo(void)//function smallest.
  59.   {
  60.     int num;
  61.     int smallest;
  62.     int bilNum=1;
  63.  
  64.     printf("\n\tEnter 5 numbers ");
  65.     printf("\n\n\tNumber %d : \n",bilNum);
  66.     scanf("%d",&num);
  67.  
  68.     smallest=num;
  69.     while (bilNum<5)
  70.     {
  71.         if(num<smallest)
  72.         smallest=num;
  73.         bilNum=bilNum+1;
  74.         printf("\tNumber %d : ",bilNum);
  75.         scanf("%d",&num);
  76.     }//end while
  77.  
  78.     printf("\n\tSmallest number: %d",smallest);
  79.     return;
  80.   }//end function Smallest.
  81.  
  82.  
  83.   void largestNo(void)
  84.   {
  85.     int num;
  86.     int largest;
  87.     int bilNum=1;
  88.  
  89.     printf("\n\tEnter five numbers:\n\n");
  90.  
  91.         num=0;
  92.         largest=0;
  93.     while (bilNum<6)
  94.     {
  95.         printf("\tNumber %d : ",bilNum);
  96.         scanf("%d",&num);
  97.  
  98.         if(num>largest)
  99.         largest=num;
  100.  
  101.         bilNum=bilNum+1;
  102.  
  103.     }//end while
  104.     printf("\n\tLargest number: %d",largest);
  105.     return;
  106.  
  107.   }//end function Largest.
  108.  
  109.  
  110.  
  111.   void sum(void)
  112.   {
  113.     int num,sum,bilNum;
  114.         bilNum=1;
  115.         sum=0;
  116.     printf("\n\tEnter five numbers:\n\n");
  117.  
  118.       while (bilNum<6)
  119.         {
  120.         printf("\tNumber %d : ",bilNum);
  121.         scanf("%d",&num);
  122.  
  123.         sum=sum+num;
  124.  
  125.         bilNum=bilNum+1;
  126.  
  127.         }//end while
  128.     printf("\n\tSum of the numbers: %d",sum);
  129.     return;
  130.   }//end function Sum
  131.  
  132.   void average(void)
  133.   {
  134.     int num,bilNum;
  135.     float sum,average;
  136.  
  137.         bilNum=1;
  138.         sum=0;
  139.         average=0;
  140.         printf("\n\tEnter five numbers:\n\n");
  141.  
  142.       while (bilNum<6)
  143.       {
  144.         printf("\tNumber %d : ",bilNum);
  145.         scanf("%d",&num);
  146.  
  147.         sum=sum+num;
  148.         average=sum/bilNum;
  149.  
  150.         bilNum=bilNum+1;
  151.  
  152.         }//end while
  153.     printf("\n\tAverage of the numbers: %.2f",average);
  154.  
  155.     return;
  156.   }//end function Average
  157.  
  158.   void Exit(void)
  159.   {
  160.      printf("\n\tYou are now exit from the program..thank you");
  161.  
  162.      return; //end function exit
  163.   }
  164.  
Feb 5 '10 #1
3 1613
weaknessforcats
9,208 Expert Mod 8TB
Exactly what are you trying to fix?
Feb 6 '10 #2
donbock
2,426 Expert 2GB
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?
Feb 6 '10 #3
weaknessforcats:
thing is i want user to enter their 5 number first and then ask them to choose to find smallest,largest 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?
Feb 7 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: ian justice | last post by:
Before i post actual code, as i need a speedyish reply. Can i first ask if anyone knows off the top of their head, if there is a likely obvious cause to the following problem. For the moment i've...
2
by: chichi | last post by:
Hi there! I was wondering if somebody could tell me how to edit the following ASP code so that the text within the tables appears as Font Color "00FF00". Right now it is appearing in BLACK and...
2
by: fish | last post by:
Hi, I have an HTML page with a FORM and some input fields. On the fields I wish to do validation as the punters change the field values. If they get it wrong, then I tell them and then wish...
7
by: juglesh | last post by:
Hello, I would like to be able to have the user sort a list of items similarly to the way you sort your queue on Netflix.com. (the numbers dont change dynamically on netflix, they must be doing...
2
by: cs168 | last post by:
Hi I am new in ASP programming so I do use the very basic and simple way to do all my stuff. Now I do really got stuck at how can I loop thru the calculation for all my selection.. My full code is as...
9
by: Frederik | last post by:
Hi all, I'm building a C# application that uses a M$ Acces database. In one of the queries I use something like the following: SELECT id FROM mytable WHERE id IN (20, 12, 21, 14) The result...
2
by: Greg Strong | last post by:
Hello All, Is it possible to change table field lookup properties in code? I've been able to change other field properties in code, however so far no luck with field lookup properties. What...
3
by: brm6546545 | last post by:
I have a tblTax. It has fields InvoiceNum, TaxAuthority, TaxableTotal, NonTaxableTotal, TaxCollected. Sample data 1,county,10.00,0.00,0.40 1,city,10.00,0.00,0.10 2,state,0.00,15.00,0.15 ...
10
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio...
5
by: thatcollegeguy | last post by:
Below are my 3php and 2js files. I create a table using ajax/php and then want to change the values in the tables add(+ number for teamid) id's for each specific td in the table. I don't know...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.