1 Attachment(s)
I need help on Array Question.
Code:
My exercise question is:
Write a program that takes in the students' marks - full marks is 100 (Test 1, Test 2 and Final). After that it will display the total marks and average marks that they get. Use array to solve your problem. Display the final result in the form of:
Student Test1 Test2 Final Total Average
1
2
3
My solution is:
#include<iostream>
#include<iomanip>
using namespace std;
void sum(const int list1[], const int list2[], const int list3[], int list4[], int size)
{
for (int i=0 ; i<size ; i++)
{
[I] list4[i] = list1[i] + list2[i] + list3;
}
return;
}
void avrg(int list4[], double list5[], int size)
{
for (int i=0 ; i<size ; i++)
{
[I] list5[i] = list4/3;
}
return;
}
int main()
{
int size=0;
int test1[size], test2[size], final[size], total[size];
double average[size];
cout << "Enter the number of student: ";
cin >> size;
cout << endl;
cout << "Enter the mark for Test 1 of each student: \n";
for (int i=0 ; i<size ; i++)
{
cout << "Student[" << i+1 << "]: ";
[I] cin >> test1;
}
cout << endl;
cout << "Enter the mark for Test 2 of each student: \n";
for (int i=0 ; i<size ; i++)
{
cout << "Student[" << i+1 << "]: ";
[I] cin >> test2;
}
cout << endl;
cout << "Enter the mark for Final Test of each student: \n";
for (int i=0 ; i<size ; i++)
{
cout << "Student[" << i+1 << "]: ";
[I] cin >> final;
}
sum(test1,test2,final,total,size);
avrg(total,average,size);
cout << endl;
cout << "Student" << setw(7) << right << "Test1" << setw(7) << "Test2" <<
setw(7) << "Final" << setw(7) << "Total" << setw(9) << "Average\n";
for (int i=0 ; i<size ; i++)
{
[I] cout << setw(7) << left << i+1 << setw(7) << right << test1 << setw(7) <<
[I] test2[i] << setw(7) << final[i] << setw(7) << total << setw(9) << fixed <<
[I] setprecision(2) << average << endl;
}
system("pause");
return 0;
}
but i get the result appear some unwanted number inside the program.
Attachment 11135
Who can help me?