Thread: What do I do when there's more than 1 mode?

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    16

    What do I do when there's more than 1 mode?

    Hi. My program is supposed to find the average & mode of a set of 6 integers. This is what I have:


    PHP Code:
    #include<stdio.h>

    int main()
    {
        
    int temp[6], iavgmode;


        
    printf("Enter 6 integers: *REMEMBER TO PRESS ENTER BETWEEN EACH INTEGER!* ");
        for(
    i=0i<6i++){
            
    scanf("%d", &temp[i]);

        }

        
    /*average*/

        
    avg 0;
        for(
    i=0i<6i++){
            
    avg avg+temp[i];}
        
    printf("Average temperature: %d\n"avg/6);

                    
    /*mode*/
        
    for(i=0i<6i++){
            if(
    temp[i]== temp[i+1]){
                
    mode=temp[i];
                }
            else{
                
    mode=0;}
        }

        
    printf("Mode is: %d\n"mode);
        return 
    0;
        } 
    The problem is that if there should be two modes(ex. 2, 4, 8, 4, 6, 8) it will only display one of them. Any advice how to correct this problem is greatly appreciated.

    Thank You.

  2. #2
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    maybe a frequency table would help. Here is an example then check for more than one in the table.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. console mode and service mode
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 06-01-2008, 01:42 AM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  3. Shortening main
    By pdstatha in forum C Programming
    Replies: 1
    Last Post: 04-03-2002, 04:56 PM
  4. Implementing "ls -al"
    By pdstatha in forum Linux Programming
    Replies: 11
    Last Post: 03-20-2002, 04:39 AM
  5. free() usage
    By pdstatha in forum C Programming
    Replies: 5
    Last Post: 03-13-2002, 09:28 AM