Thread: project help (mead,median,mode)

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    1

    Question project help (mead,median,mode)

    Hi ppl i have being workig on this project for weeks and im a novice when it comes to c programming so if any1 can help please do so.

    im trying to make a program where the user is asked if they would like to enter (4-20) numbers manually or randomly generate (4-200) numbers. Display whichever choice, then if they would like to display the mean, median, mode or all three. Afterwards the program should ask if the user would like to repeat the program or exit.

    this was my plan:

    Would you like to: 1 - manually enter (4-20) numbers
    2 - randomly generate (4-200) numbers

    Then ask: which would you like to display :1- Mean
    2 - Median
    3 - Mode
    4 - All three

    Would you like to repeat the program: 1 - Yes
    2 - No

    My code so far as you can tell i am quite bad at it:

    Code:
    #include<stdio.h>
    #include<math.h>
    
    main() {
      float a,b;
      int instr;
      
      int one;
        int two;
        int three;
        int four;
        int five;
        int six;
        int seven;
        int eight;
        int nine;
        int ten;
        int eleven;
        int twelve;
        int thirteen;
        int fourteen;
        int fifthteen;
        int sixteen;
        int seventeen;
        int eighteen;
        int nineteen;
        int twenty;
        int m;
        
      printf("Welcome!!!\n\nThis Program Calculates the Mean, Median and Mode of:\n\na. Manually Entered Numbers Ranging Between 4-20 or\n\nb. Randomly Generated numbers ranging from 4-200 ");
      
      printf("\n\n\n\nPlease Make A choice\n\n1. for Random Numbers(4-200)\n\n2. for Manually entering Numbers(4-20): ");
      scanf("%d[20]",&instr);
      
      if (instr == 1) {
        printf("The random Numbers are:"\n);
      }
    else {
        if (instr == 2) {
          printf("Please Enter Your Values (4-20)\n");
        
    
        
        
        
        
       { 
        printf("Enter value one: \n");
      scanf("%f",&one);
        
       printf("Enter value two: \n");
      scanf("%f",&two); 
      
      printf("Enter value three: \n");
      scanf("%f",&three);
            
       printf("Enter value four: \n");
      scanf("%f",&four);     
            
       printf("Enter value five: \n");
      scanf("%f",&five);
      
      printf("Enter value six: \n");
      scanf("%f",&six);
      
      printf("Enter value seven: \n");
      scanf("%f",&seven);
      
      printf("Enter value eight: \n");
      scanf("%f",&eight);
      
      printf("Enter value nine: \n");
      scanf("%f",&nine);
      
      printf("Enter value ten: \n");
      scanf("%f",&ten);
      
      printf("Enter value eleven: \n");
      scanf("%f",&eleven);
      
      printf("Enter value twelve: \n");
      scanf("%f",&twelve);
      
      printf("Enter value thirteen: \n");
      scanf("%f",&thirteen);
      
      printf("Enter value fourteen: \n");
      scanf("%f",&fourteen);
      
      printf("Enter value fifteen: \n");
      scanf("%f",&fifteen);
      
      printf("Enter value sixteen: \n");
      scanf("%f",&sixteen);
      
      printf("Enter value seventeen: \n");
      scanf("%f",&seventeen);
      
      printf("Enter value eighteen: \n");
      scanf("%f",&eighteen);
      
      printf("Enter value nineteen: \n");
      scanf("%f",&nineteen);
      
      printf("Enter value twenty: \n");
      scanf("%f",&twenty);
         
       
       m = (one + two + three + four + five + six + seven + eight + nine + ten + eleven + twelve + thirteen + fourteen + fifteen + sixteen + seventeen + eighteen + nineteen + twenty)/20;
          
      printf("The mean for these values is: %f\n", m);
        
         }
         
          else {
    	printf("Not a valid command.\n");
          }
      
      
      
      printf("1 - Mean\n2 - Median\n3 - Mode\n4 - All three\nChoice : ");
      scanf("%d",&instr);
     
          }
          else {
    	printf("Not a valid command.\n");
          }
        }
      }

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Sounds like a good plan. You might want to consider using an array for the numbers. Also, you're declaring all of the numbers as ints, but telling scanf() to treat them as floats:
    Code:
    float numbers[20];
    int i;
    
    for(i = 0;i < 20;++i)
    {
      printf("Enter value &#37;d:\n", i + 1);
      scanf("%f", &numbers[i]);
    }
    Then to solve for m you might want to try:
    Code:
    float m = 0.;
    
    for(i = 0;i < 20;++i)
      m += numbers[i];
    m = total / 20;
    Last edited by itsme86; 04-09-2007 at 05:11 PM.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 09:05 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  3. Dynamic Binding
    By gpr1me in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2006, 09:01 AM
  4. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM