| 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 | |
|
|
|
| new cppUser (18) | |
|
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. | |
|
|
|
| closed account (4y79216C) | |
| if i put a name and enter their score | |
|
|
|
| fun2code (1227) | ||||||
You have errors in finding the largest and smallest. Example here for largest:
You want to assign that for the initial value, then search for larger values:
Same for finding lowest. This should help.
| ||||||
|
|
||||||
| cire (2347) | |
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. | |
|
|
|
| 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
|
|
| fun2code (1227) | |
|
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
|
|
| closed account (4y79216C) | |||
this is my right now
| |||
|
Last edited on
|
|||
| 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??? | |
|
|
|
| cire (2347) | |
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. | |
|
|
|
| closed account (4y79216C) | |||
is this right <<name[0]?? | |||
|
|
|||
| closed account (4y79216C) | |
| my only problem is the name ?? | |
|
|
|
| fun2code (1227) | |||
|
re-check cires post above. And re lines 42, 43 surely you mean:
| |||
|
Last edited on
|
|||
| 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??? | |
|
|
|
| Imadatobanisa (647) | |
|
You should initiate your min (lowest score) with first element value. min = array[0]; | |
|
Last edited on
|
|
| closed account (4y79216C) | |||
|
ok i will try now thanks like this
?? | |||
|
Last edited on
|
|||
| closed account (4y79216C) | |
| i think it needs 2 temp??? | |
|
|
|
| Imadatobanisa (647) | |||
Here's how to get a correct result :
| |||
|
|
|||
| closed account (4y79216C) | |
|
when i enter first the and second is lowest and might be always the higgest score | |
|
|
|
| Imadatobanisa (647) | |
| Be more detailed? E.g post an example here... | |
|
|
|