954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Finding the Highest and Lowest Score

Write a program that will read in 10 test scores. Print out all 10 scores, then print the highest score, and then the lowest score.

Ok i got this so far but i do not know how to print the highest or lowest.

#include<iostream>
using namespace std;
int main()
{
int score;
int t[10];
while(cin >> t[10])
{
cout << t[10] << endl;
}
}
bigdog1
Newbie Poster
1 post since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

1) Use code tags, [code ] /* put code here */ [code]
2) You code is not doing what you think it is doing.
3) To make it do what you think its doing, you need to use loop(s).
4) Create a min and max variable. Whenever the user enters a number
update the min and max variable so that it points to the correct value.

firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
 
int t[10];
while(cin >> t[10])


Be careful. You declare an array of size 10. This will begin at t[0] and go up to t[9]. You're trying to put data into location t[10] which isn't part of the array. This may crash your program.

What I assume you want to do is to enter 10 integers into the array. To do this use a for loop like this:

for (int i = 0; i < 10; i++)
{
    cout << "Enter next integer: "; //Don't really need this line
     cin >> t[i];
}
necrolin
Posting Whiz in Training
225 posts since Jun 2009
Reputation Points: 105
Solved Threads: 26
 
1) Use code tags, [code ] /* put code here */ [code]

Small correction here:[code] /* put code here */ [/code]

Nick Evan
Not a Llama
Moderator
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: