Click here to Skip to main content
15,909,827 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Difficult computer science problem Pin
Michael Dunn3-Oct-06 5:04
sitebuilderMichael Dunn3-Oct-06 5:04 
GeneralRe: Difficult computer science problem Pin
Semion_N3-Oct-06 5:06
Semion_N3-Oct-06 5:06 
AnswerRe: Difficult computer science problem Pin
led mike3-Oct-06 5:13
led mike3-Oct-06 5:13 
GeneralRe: Difficult computer science problem Pin
toxcct3-Oct-06 5:27
toxcct3-Oct-06 5:27 
GeneralRe: Difficult computer science problem Pin
led mike3-Oct-06 8:20
led mike3-Oct-06 8:20 
GeneralRe: Difficult computer science problem Pin
David Crow3-Oct-06 5:48
David Crow3-Oct-06 5:48 
AnswerRe: Difficult computer science problem Pin
Maximilien3-Oct-06 5:47
Maximilien3-Oct-06 5:47 
AnswerRe: Difficult computer science problem Pin
benjymous3-Oct-06 5:54
benjymous3-Oct-06 5:54 
I'm guessing recursion is your friend here, assuming a magic computer that'll never stack overflow

Pseudo-C-ish-code
above_average = 0;

void main()
{
  doit(0,0)
  print( above_average " of your numbers were above average )
}

int doit( int sum, int count )
{
  print( "enter number, -1 to end" );
  int input
  get input from keyboard

  int average;
  if input == -1
  {
    average = sum/count
  }
  else
  {
    average = doit(sum+input, count+1)
    if( input > average )
    {
      above_average++
    }
  }
  return average 
}


Now remember, your lecturer is probably reading these forums....

(Technically, this is using a stack, just not the kind of stack most people would think of!)

--
Help me! I'm turning into a grapefruit!
Buzzwords!

GeneralRe: Difficult computer science problem Pin
David Crow3-Oct-06 6:00
David Crow3-Oct-06 6:00 
GeneralRe: Difficult computer science problem Pin
Chris Losinger3-Oct-06 7:52
professionalChris Losinger3-Oct-06 7:52 
QuestionClient Server Application Pin
Pardi Banjarnahor3-Oct-06 4:06
Pardi Banjarnahor3-Oct-06 4:06 
AnswerRe: Client Server Application Pin
_AnsHUMAN_ 3-Oct-06 4:12
_AnsHUMAN_ 3-Oct-06 4:12 
AnswerRe: Client Server Application Pin
Rajesh R Subramanian3-Oct-06 4:16
professionalRajesh R Subramanian3-Oct-06 4:16 
AnswerRe: Client Server Application Pin
Hamid_RT3-Oct-06 9:18
Hamid_RT3-Oct-06 9:18 
QuestionHow do I pack to integer values in a double ? Pin
Astricks3-Oct-06 3:45
Astricks3-Oct-06 3:45 
AnswerRe: How do I pack to integer values in a double ? Pin
toxcct3-Oct-06 3:49
toxcct3-Oct-06 3:49 
GeneralRe: How do I pack to integer values in a double ? Pin
Astricks3-Oct-06 3:59
Astricks3-Oct-06 3:59 
GeneralRe: How do I pack to integer values in a double ? Pin
toxcct3-Oct-06 4:03
toxcct3-Oct-06 4:03 
GeneralRe: How do I pack to integer values in a double ? Pin
Astricks3-Oct-06 4:19
Astricks3-Oct-06 4:19 
GeneralRe: How do I pack to integer values in a double ? Pin
Chris Losinger3-Oct-06 4:21
professionalChris Losinger3-Oct-06 4:21 
GeneralRe: How do I pack to integer values in a double ? Pin
Astricks3-Oct-06 4:45
Astricks3-Oct-06 4:45 
GeneralRe: How do I pack to integer values in a double ? Pin
Astricks3-Oct-06 4:53
Astricks3-Oct-06 4:53 
QuestionRe: How do I pack to integer values in a double ? Pin
David Crow3-Oct-06 4:40
David Crow3-Oct-06 4:40 
JokeRe: How do I pack to integer values in a double ? Pin
toxcct3-Oct-06 4:45
toxcct3-Oct-06 4:45 
GeneralRe: How do I pack to integer values in a double ? Pin
David Crow3-Oct-06 4:46
David Crow3-Oct-06 4:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.