Thread: code

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    1

    Angry code

    can't get the mode for this program. it's supposed to give me the grade that is repeated the most times, for example: if i enter 3,4,3,5,2 the mode should be 3.
    please help me with this!!!!!

  2. #2
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    how is it supposed to give you three when your just outputting what i enter?

  3. #3
    looking for the truth moemen ahmed's Avatar
    Join Date
    Feb 2002
    Location
    Egypt
    Posts
    161
    here s the code
    Code:
    #include <iostream>
    #include <conio.h>
    float most_repeated(float*);
    float most_repetead(float* g,int no){
       float r[no];
       float  most_rep=0;
    
       for (int counter1=0;counter1<no;counter1++)
       {
            for (int counter2=0;counter2<no;counter2++)
            {
                 if (g[counter1]==g[counter2]) r[counter1]++;
            }
       }
         for (int counter3=0;counter3<no;counter3++)
       {
           if (r[counter3]>most_rep) most_rep=g[counter3];
       }
       return most_rep;
       }
    
    void main()
    
    {
    
    	int numgrades;
           float *grades;
    		
    		
    		cout<<"how many grades you wnat to enter: "<<endl;
    		cin>>numgrades;
    		grades = new float[numgrades];
    		
    		
    		
    		for (int count = 0; count <numgrades; count++)
    	{
    
    		cout<<"grades " << (count + 1)<<":";
    		cin>>grades[count];
    
    	}
    
    	for (int count = 0; count <numgrades; count++)
    	{
    		
    		cout<<grades[count]<<" ";
    
    	}
    cout<<endl;
    float The_most_repeated=most_repetead(grades,numgrades);
    
    cout<<"the most repeated grade is "<<The_most_repeated<<endl;
    getche();
    
    return 0;
    
    
    }
    i hope it helps
    Programming is a high logical enjoyable art for both programer and user !!

  4. #4
    Attack hamster fuh's Avatar
    Join Date
    Dec 2002
    Posts
    176
    Don't use void main(). Use int main(). And it won't compile. You need using namespace std;, change the header to iostream.h (I don't recomend that), or use std::cout, std::cin, and std::endl.
    Stupid things pop singers say

    "I get to go to lots of overseas places, like Canada."
    - Britney Spears

    "I love what you've done with the place!"
    -Jessica Simpson upon meeting the Secretary of Interior during tour of the White House

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM