little to fix it array(little hey little ho)

Pages: 12
Dec 22, 2012 at 7:54am
closed account (4y79216C)
hello again people in the world can somebody help me ....
a little to fix it, it just the lowest and average

here's my code
#include<iostream>
using namespace std;
int main()
{

string name[1000] = {};
int score[]={};
int i;
int hn;



int largest=0;
int smallest=0;

float average;




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

for(i=0; i<hn; i++)
{
cout << "ENTER name of students :"<<i+1;

cin >> name[i];

cout << "ENTER EMUH SCORE:";
cin>>score[i];
cout<<"\n";
}


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



for(i=0;i<hn-1;i++){

if(score[i]<smallest)
smallest=score[i];
smallest=score[0];}
average=score[i]/hn;

cout<<"HIGHEST SCORE IS: "<<largest<<name[i]<<endl;
cout<<"LOWEST SCORE IS:"<<smallest<<name[i+1]<<endl;
cout<<"AVERAGE IS:"<<average;
system("PAUSE");



and heres the problem

. 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
save as prelim3-class 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 really appreciate who will answer

Dec 22, 2012 at 9:43am
I have a few tips:
1) Take advantage of the [code] [/code] tags to put your code in. It makes it more readable.

2) Don't post multiple times and don't have the Internet do your homework for you.
Question continued from:
http://www.cplusplus.com/forum/beginner/88573/
http://www.cplusplus.com/forum/general/88302/
http://www.cplusplus.com/forum/windows/88167/
http://cplusplus.com/forum/beginner/88083/

3) What is your problem/error? What 'little fix' do you want?

4) Stick to one thread. Don't make multiple threads for the same program.
Dec 24, 2012 at 2:46am
closed account (4y79216C)
if i put a name and enter their score
Dec 24, 2012 at 5:15am
closed account (D80DSL3A)
You have errors in finding the largest and smallest. Example here for largest:
1
2
3
4
for(i=0;i<hn;i++){
if(score[i]>largest)
largest=score[0];// this line resets the value every loop (bad)
largest=score[i];}

You want to assign that for the initial value, then search for larger values:
1
2
3
4
largest=score[0];
for(i=0;i<hn;i++){
if(score[i]>largest)
largest=score[i];}

Same for finding lowest.
This should help.

little hey little ho
Is that a Stewart Little reference?
Dec 24, 2012 at 10:53am
int score[]={};

This is not legal code. If it were legal code, accessing it as if it had any elements wouldn't make any sense.
Dec 25, 2012 at 6:25am
closed account (4y79216C)
its difficult to find the average to
average=score[i]+score[i]/score[0];



s this the right to find the average?
Merr Christmas to all

yes fun2code little hey little ho
Last edited on Dec 25, 2012 at 6:42am
Dec 25, 2012 at 9:31pm
closed account (D80DSL3A)
To find the average you should add up all the scores, then divide by the number of scores.
Declare an int scoreSum = 0;
Then, in either of your for loops add up the values:
scoreSum += score[i];

After adding all values you can find: average = scoreSum/hn;

You still need to declare a size for the scores array.
int score[]={}; isn't going to work out.

Little high little low?
Last edited on Dec 26, 2012 at 12:15am
Dec 28, 2012 at 10:08am
closed account (4y79216C)
this is my right now
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
46
47
48
49
50
51



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

	string name[1000] = {};
	int score[]={};
	int i;
	int hn;
	int largest=0;
	int smallest=0;
	int scoresum=0;
    float average;
	
    
   
    cout<<"ENTER MANY many students?:" ;
	cin>>hn;
cout<<"\n";
	for(i=0; i<hn; i++)
	{
		cout << "ENTER name of students :#"<<i+1<<"\t";
        
        cin >> name[i];	
		cout << "ENTER EMUH SCORE:";
		cin>>score[i];
cout<<"\n";
       scoresum+=score[i];     }
    

    for(i=0;i<hn;i++){
    if(score[i]>largest)
    largest=score[i];}
    for(i=0;i<hn-1;i++){
    if(score[i]>smallest)
    
    smallest=score[i];}
     
    average=score[i]/hn;
    
     cout<<"HIGHEST SCORE IS: "<<name[i]<<endl;
     cout<<"LOWEST SCORE IS:"<<name[0]<<endl;
     cout<<"AVERAGE IS:"<<average;
system("PAUSE");

	
}
 
Last edited on Dec 30, 2012 at 12:05am
Dec 28, 2012 at 10:14am
closed account (4y79216C)
hmmm, i think why the average didn't work because of the last part
cout<<"HIGHEST SCORE IS: "<<name[i]<<endl;
cout<<"LOWEST SCORE IS:"<<name[0]<<endl;
i dont if this is the w <<name[0];
example of my output

how many student?2
enter student #1 name:james
enter ssuden score :50

enter student #1 name: little hey
enter sruden tscore :100
the highest score is: little hey
the lowest score is: james
average is:50


but when i enter this

how many student?2
enter student #1 name:james
enter ssuden score :100

enter student #1 name: little hey
enter sruden tscore :50
the highest score is: little hey
the lowest score is: james
average is:25

i think it is because of name[0];
what should i do???

Dec 28, 2012 at 3:49pm
int score[]={};

This is still illegal code, and it still fails to allocate any memory for the score array.


average=score[i]/hn;

score[i] is not the sum of all scores.
Dec 29, 2012 at 7:53am
closed account (4y79216C)
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
46
47
48
49
50

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

string name[1000] = {};
int score[]={};
int i;
int hn;
int largest=0;
int smallest=0;
int scoresum=0;
float average;



cout<<"ENTER MANY many students?:" ;
cin>>hn;
cout<<"\n";
for(i=0; i<hn; i++)
{
cout << "ENTER name of students :#"<<i+1<<"\t";

cin >> name[i];	
cout << "ENTER EMUH SCORE:";
cin>>score[i];
cout<<"\n";
scoresum+=score[i]; }


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

smallest=score[i];}

average=score[i]/hn;

cout<<"HIGHEST SCORE IS: "<<name[i]<<endl;
cout<<"LOWEST SCORE IS:"<<name[0]<<endl;
cout<<"AVERAGE IS:"<<average;
system("PAUSE");


}


is this right <<name[0]??

Dec 30, 2012 at 12:01am
closed account (4y79216C)
my only problem is the name ??
Dec 30, 2012 at 12:12am
closed account (D80DSL3A)
re-check cires post above.

And re lines 42, 43 surely you mean:
1
2
cout<<"HIGHEST SCORE IS: "<<largest<<endl;
cout<<"LOWEST SCORE IS:"<<smallest<<endl;
Last edited on Dec 30, 2012 at 12:15am
Dec 30, 2012 at 12:34am
closed account (4y79216C)
when i enter it would be like this
ENTER MANY many students?2
ENTER name of students:hey
ENTER EMUH SCORE:3
ENTER name of students:ii
ENTER EMUH SCORE:6
HIGHEST SCORE IS:6
LOWEST SCORE IS:0
hhhmmm???
Dec 30, 2012 at 12:37am
You should initiate your min (lowest score) with first element value.
min = array[0];
Last edited on Dec 30, 2012 at 12:37am
Dec 30, 2012 at 12:52am
closed account (4y79216C)
ok i will try now thanks

like this
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
46
47
48
49
50

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

string name[1000] = {};
int score[]={};
int i;
int hn;
int max;
int min;
int scoresum;
float average;


cout<<"ENTER MANY many students?:" ;
cin>>hn;
cout<<"\n";
for(i=0; i<hn; i++)
{
cout << "ENTER name of students :#"<<i+1<<"\t";

cin >> name[i];	
cout << "ENTER EMUH SCORE:";
cin>>score[i];
cout<<"\n";}
scoresum+=score[i];

max=0;
for(i=0;i<hn;i++){
if(score[i]>max){
   max=score[i];
}
}
min=0;
for(i=0;i<hn-1;i++){
if(score[i]<min)
   min=score[i];{
}
}

average=score[i]/hn;

cout<<"HIGHEST SCORE IS: "<<max<<endl;
cout<<"LOWEST SCORE IS:"<<min<<endl;
cout<<"AVERAGE IS:"<<average;
system("PAUSE");

}

??
Last edited on Dec 30, 2012 at 12:58am
Dec 30, 2012 at 1:05am
closed account (4y79216C)
i think it needs 2 temp???
Dec 30, 2012 at 1:55am
Here's how to get a correct result :

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
46
47
48
49
#include<iostream>
using namespace std;
int main()
{

string name[1000] = {};
int score[]={};
int i;
int hn;
int max;
int min;
int scoresum;
float average;


cout<<"ENTER MANY many students?:" ;
cin>>hn;
cout<<"\n";
for(i=0; i<hn; i++)
{
cout << "ENTER name of students :#"<<i+1<<"\t";

cin >> name[i];	
cout << "ENTER EMUH SCORE:";
cin>>score[i];
cout<<"\n";}
scoresum+=score[i];

max=score[0]; //Edited
for(i=1;i<hn;i++){
if(score[i]>max){
   max=score[i];
}
}
min=score[0]; //Edited
for(i=1;i<hn-1;i++){
if(score[i]<min)
   min=score[i];{
}
}

average=score[i]/hn;

cout<<"HIGHEST SCORE IS: "<<max<<endl;
cout<<"LOWEST SCORE IS:"<<min<<endl;
cout<<"AVERAGE IS:"<<average;
system("PAUSE");

}
Dec 30, 2012 at 2:16am
closed account (4y79216C)
when i enter first the and second is lowest
and might be always the higgest score
Dec 30, 2012 at 2:30am
Be more detailed? E.g post an example here...
Pages: 12