5
Contributors
6
Replies
10
Views
5 Years
Discussion Span
Last Post by Salem
Featured Replies
  • 4
    Salem 5,138   5 Years Ago

    Get someone to read these numbers to you, and you try to remember what the highest and lowest numbers you hear. 31 47 85 64 95 48 45 86 26 61 47 76 98 80 62 19 4 12 10 78 Read More

  • 1
    Narue 5,707   5 Years Ago

    [QUOTE=Chilton;1606630]Use a vector.[/QUOTE] "Without using an array" generally means "without storing all of the numbers", which means vector is out too. But even if you could store all of the numbers, doing so would be stupid because it's trivial to write a linear algorithm without wasting memory like that. Read More

  • 5
    Salem 5,138   5 Years Ago

    And what do you suppose they might learn from that spoon-fed answer on a plate? [B][U]Don't give away code![/U][/B] [url]http://www.daniweb.com/software-development/cpp/threads/78223[/url] All that's going to happen is they'll hand this in without having much of a clue, so that when next week's homework comes around (say sorting numbers), they're totally screwed … Read More

4

Get someone to read these numbers to you, and you try to remember what the highest and lowest numbers you hear.

31
47
85
64
95
48
45
86
26
61
47
76
98
80
62
19
4
12
10
78

1

Use a vector.

"Without using an array" generally means "without storing all of the numbers", which means vector is out too. But even if you could store all of the numbers, doing so would be stupid because it's trivial to write a linear algorithm without wasting memory like that.

0

True enough. I assumed wrongly that it had more to do with setting a specific size of an array, with regards to allocation and things like that. Also, since the program isn't really asking for the set of data but only the largest and smallest out of those entered, it doesn't make sense.

-1

Easy enough, assuming some things.

int maxVal  = INT_MIN;
int minVal = INT_MAX;
int input = -1;
const int END  = -1;
while( cin >> input ){
  if( input == END) break;
  else{
    minVal = std::min(minVal,input);
    maxVal = std::max(maxVal,input);
  }
}
This article has been dead for over six months. Start a new discussion instead.
Be sure to adhere to our posting rules.