one dimensional

closed account (4y79216C)
help me plssss..
i really dont know whast will gonna be next someone help me
the problem is this...
write a program that allows the user to enter students name followed by their test score. it will first ask how many students to enter, then asks the students name followed by their score. it will then output the average of all scores, & the student w/ the highest & lowest test score. use one dimensional array for students name & another array for the score

expected output
how many student?2
enter student #1 name:tony
enter sruden tscore 50
enter student #1 name:t
enter sruden tscore 100
the highest score is t
the lowest score is tony
average is


i think my variables are not correct..

#include<iostream>
using namespace std;
int main()
{

string name[50]={};
int s[]={};
int i;
int hn;
int l;
int k;
int n;
int largest;
int smallest;

float average;
cout<<"ENTER MANY many students?:"<<endl;
cin>>hn;
for(i=1;i<hn;i++)
{
cout<<"ENTER name of students :"<<i<<":" ;
cin>>n;{
cout<<"ENTER SCORE:";
cin>>l;}

for(i=0;i<hn;i++){
if(s[i]>largest)
largest=s[i];

for(i=0;i<hn-1;i++){
if(s[i]<smallest)
smallest=s[i];}

}}

cout<<"THE HIGHEST IS"<<s[i];



system("PAUSE");
}
int s[]={};

that array needs to have a size
closed account (4y79216C)
for what?
if u don't mind.
Last edited on
arrays need to have a size.
if you don't know the size, use a pointer or std::vector
if this array does not need more than 1 entry, just use an integer variable
closed account (4y79216C)
but how about my looping?
that's your code.
just edited it a little to make it easier to read

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<iostream>
using namespace std;

int main()
{
	string name[50] = {};
	int s[] = {};
	int i;
	int hn;
	int l;
	int k;
	int n;
	int largest;
	int smallest;

	float average;
	cout << "ENTER MANY many students?:" << endl;
	cin >> hn;

	for(i=1; i<hn; ++i)
	{
		cout << "ENTER name of students :" << i << ":";
		cin >> n;
		{
			cout << "ENTER SCORE:";
			cin >> l;
		}

		for(i=0; i<hn; ++i)
		{
			if(s[i] > largest)
				largest = s[i];

			for(i=0; i<hn-1; ++i)
			{
				if(s[i] < smallest)
					smallest = s[i];
			}
		}
	}

	cout << "THE HIGHEST IS" << s[i];

	system("PAUSE");
}
Last edited on
line 7 the array has no size

line 11 k never gets used

line 16 average never gets used

what are the brackets in line 24 and 27 for?

line 31 largest has no value

line 36 smallest has no value
Last edited on
closed account (4y79216C)
thank you for anything
but i have to sleep now :(
early school tomorrow..
closed account (4y79216C)
its already 10:05 in the evening

edit will be tomorrow
closed account (4y79216C)
I could not understand my code :(
Topic archived. No new replies allowed.