0

hi, i'm working on an assignment for school, and i'm having a lot of problems when i try to compile it. one of the errors is about changing the functions into arrays and getting an error about pointers, and another is trying to get the right info to the right place. i know its kind of long, but if you could help me, i'd be very grateful.

#include<iostream>
using namespace std;

struct Student {
	char name [51];
	int hwScore[6];
	int midterm;
	int exam;
};

void input(Student& student);
double score (Student student);
void display (Student student[], double total[]);
int minIndex (double totalScore[], int size, int startIndex);
void swap(double totalScore[], int i, int j);
void swap2(Student student[], int i, int j);
void sort (double totalScore[], int size, Student student[]);

int main(){
	double totalScore [100];
	char again;
	Student student[100];
	int i = 0;
		
	do 
	{
		input (student[i]);
		totalScore[i] = score(student[i]);
		cout << student[i].name << "'s final score is : ";
		cout << totalScore[i] << endl;
		cout << "Enter more students? (Y or N): ";
		cin >> again;
		cout << endl;
		i++;
		cin.ignore (1, '/n');
	}while (again == 'y' || again == 'Y');

	sort(totalScore[], 100, student[]);
	for (int i = 0; i < 100; i++)
		display(student, totalScore[i]);







	return 0;
}


void input (Student& student)
{
	cout << "Enter student name: ";
	cin.getline (student.name, 51);
	cout << endl;

	for (int i=0; i < 6; i++)
	{
		int hwNum = i;
		cout << "Enter hw " << hwNum + 1 << "(max 10): ";
		cin >> student.hwScore[i];
			
		while ((student.hwScore[i] > 10) || (student.hwScore[i] < 0))
		{
			cout << "Invalid input, please enter a number from 0 to 10:" << endl;
			cin >> student.hwScore[i];
		}
	}

	cout << "Enter midterm score(max 40): ";
	cin >> student.midterm;
	while ((student.midterm > 40) || (student.midterm < 0))
		{
			cout << "Invalid input, please enter a number from 0 to 40:" << endl;
			cin >> student.midterm;
		}
	cout << "Enter final score(max 100): ";
	cin >> student.exam;
	while ((student.exam > 100) || (student.exam < 0))
		{
			cout << "Invalid input, please enter a number from 0 to 10:" << endl;
			cin >> student.exam;
		}
}

double score (Student student)
{
	double totalScore = 0;
	double totalHw =0;
	for (int i=0; i < 6; i++)
		totalHw += student.hwScore[i]; 

	totalScore =((totalHw/60 * 30) + (student.midterm/40 * 25) + (student.exam/100 * 45));
	return totalScore;
}

void display (Student student[], double total[])
{
	int i;
	cout << student[i].name << endl;
	cout << total[i];
}

int minIndex (double totalScore[], int size, int startIndex)
{
	double min = totalScore[startIndex];
	int minInd = startIndex;
	for (int i = startIndex + 1; i < size; i++)
	{
		if (min > totalScore[i]){
			minInd = i;
			min = totalScore[i];
		}
	}
return minInd;
}

void swap(double totalScore[], int i, int j)
{
	double temp = totalScore[i];
	totalScore[i] = totalScore[j];
	totalScore[j] = temp;
}

void swap2(Student student[], int i, int j)
{
	Student temp = student[i];
	student[i] = student[j];
	student[j] = temp;
}


void sort (double totalScore[], int size, Student student[])
{	
	for (int i = 0; i < size; i++)
	{
		int minInd = minIndex (totalScore, size, i);
		swap (totalScore[i], totalScore[minInd]);
		swap2 (student[i], student[minInd]);
	}
}
2
Contributors
1
Reply
2
Views
12 Years
Discussion Span
Last Post by Dave Sinkula
0
sort(totalScore[], 100, student[]);

Remove the empty brackets.

display(student, totalScore[i]);

The prototype calls for an array, you are passing a single element.

int i;
	cout << student[i].name << endl;

Uh, shouldn't i be given a value?

void swap(double totalScore[], int i, int j)
void swap2(Student student[], int i, int j)

		swap (totalScore[i], totalScore[minInd]);
		swap2 (student[i], student[minInd]);

Okay, let's play a game of count the parameters. Then let's play a game of notice the type.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.