Multimode//No mode?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2007
Posts: 15
Reputation: Ortal is an unknown quantity at this point 
Solved Threads: 0
Ortal Ortal is offline Offline
Newbie Poster

Multimode//No mode?

 
0
  #1
Apr 23rd, 2007
after hours of trying (im really new to C++), i got a program to run that will find the mean, median, mode, and standard deviation of an array of numbers. However, if there is no mode (every number only appears once), it just returns the first number for mode. if there is more then one mode, it just returns the first mode. ive tried using a few if statements, but it screwed up everything and wouldnt run. ::points down:: this way will run. any suggestions on what i can do to make it happen?




//MODE HERE
int modeIndex=0;
int modeFrequency=0;
int maxModeIndex=0;
int maxModeFrequency=0;
for(int i=0 ; i<length ; i++)
{
if(list[i]!=list[modeIndex])
{
if(modeFrequency>1)
{
cout<< list[modeIndex] << " occurs " << modeFrequency << " number of times" << endl;
}
if(modeFrequency>maxModeFrequency)
{
maxModeIndex = modeIndex;
maxModeFrequency = modeFrequency;
}
modeIndex = i;
modeFrequency=1;
}
else
{
modeFrequency++;
}
}
// validate the last set of elements in the list.
if(modeFrequency>1)
{
cout<< list[modeIndex] << " occurs " << modeFrequency << " number of times" << endl;
}
if(modeFrequency>maxModeFrequency)
{
maxModeIndex = modeIndex;
maxModeFrequency = modeFrequency;
}
cout<< "Mode is: " << list[maxModeIndex] << endl;

return 0;
Last edited by Ancient Dragon; Apr 23rd, 2007 at 11:07 pm. Reason: corrected code tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,398
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Multimode//No mode?

 
0
  #2
Apr 23rd, 2007
the formatting is really horrible -- how did you get all those color code tags there? I just simply removed the code tags to make your code readable.
Last edited by Ancient Dragon; Apr 23rd, 2007 at 11:08 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 15
Reputation: Ortal is an unknown quantity at this point 
Solved Threads: 0
Ortal Ortal is offline Offline
Newbie Poster

Re: Multimode//No mode?

 
0
  #3
Apr 23rd, 2007
the formatting of the c++ is horrible, as in the xyntax and logic? or how it copy/pasted?

i just opened up the .cpp file and copy/pasted. visual studio automatically colors my tags like that.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,398
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Multimode//No mode?

 
0
  #4
Apr 23rd, 2007
are you sure ? I've done it hundreds of times without that problem. Probably some setting you have made in the editor.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 15
Reputation: Ortal is an unknown quantity at this point 
Solved Threads: 0
Ortal Ortal is offline Offline
Newbie Poster

Re: Multimode//No mode?

 
0
  #5
Apr 23rd, 2007
can you please specify if you are talking about my actual C++ or how it appears on the firum. cause i dont know what you mean...
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,398
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Multimode//No mode?

 
0
  #6
Apr 23rd, 2007
Oh certainly. It is how it appears in the forum -- no formatting and everything in the left-hand margin. Makes it really difficult to read and most people will probably just not take the time to fiture it out.

What version of Visual Studio are you using? I don't have that problem with 2005.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 15
Reputation: Ortal is an unknown quantity at this point 
Solved Threads: 0
Ortal Ortal is offline Offline
Newbie Poster

Re: Multimode//No mode?

 
0
  #7
Apr 23rd, 2007
  1.  
  2. //MODE HERE
  3. int modeIndex=0;
  4. int modeFrequency=0;
  5. int maxModeIndex=0;
  6. int maxModeFrequency=0;
  7. for(int i=0 ; i<length ; i++)
  8. {
  9. if(list[i]!=list[modeIndex])
  10. {
  11. if(modeFrequency>1)
  12. {
  13. cout<< list[modeIndex] << " occurs " << modeFrequency << " number of times" << endl;
  14. }
  15. if(modeFrequency>maxModeFrequency)
  16. {
  17. maxModeIndex = modeIndex;
  18. maxModeFrequency = modeFrequency;
  19. }
  20. modeIndex = i;
  21. modeFrequency=1;
  22. }
  23. else
  24. {
  25. modeFrequency++;
  26. }
  27. }
  28. // validate the last set of elements in the list.
  29. if(modeFrequency>1)
  30. {
  31. cout<< list[modeIndex] << " occurs " << modeFrequency << " number of times" << endl;
  32. }
  33. if(modeFrequency>maxModeFrequency)
  34. {
  35. maxModeIndex = modeIndex;
  36. maxModeFrequency = modeFrequency;
  37. }
  38. cout<< "Mode is: " << list[maxModeIndex] << endl;
  39.  
  40. return 0;
Last edited by Ancient Dragon; Apr 23rd, 2007 at 11:42 pm. Reason: corrected code tags
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 15
Reputation: Ortal is an unknown quantity at this point 
Solved Threads: 0
Ortal Ortal is offline Offline
Newbie Poster

Re: Multimode//No mode?

 
0
  #8
Apr 23rd, 2007
better? its still showing up in colors. i pasted it into notepad first this time.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,398
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Multimode//No mode?

 
0
  #9
Apr 23rd, 2007
great work The green color is a result of code tags. Now we have something to study.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,398
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Multimode//No mode?

 
0
  #10
Apr 23rd, 2007
>>However, if there is no mode (every number only appears once), it just returns the first number for mode. if there is more then one mode, it just returns the first mode.

What behavior do you want it to do ?
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC