I have difficulty to change the following program by using the array.
The display need to be like the following:
Result 1: 50.00 Grade U
Result 2: 95.60 Grade A
Result 3: 72.00 Grade B

Can anyone tell me how to do it?
Thanks.

#include <iostream>
#include <iomanip>
using namespace std;

float calc_average(float sum, int num);
void letter(float, int);

float score = 0;
int resultNum = 0;
int inputnum = 1; // for visual appeal
float avg = 0;
long sum = 0;
float high = 0;
float low = 100;

void main()
{
	do
	{
		cout << "Enter result " << inputnum << " (or -1 if no more results) ";
		cin >> score;

		if (score<60)
			cout << "Result " << resultNum << " is a U\n";

		if (score>=60 && score<70)
			cout << "Result " << resultNum << " is a C\n";

		if (score>=70 && score<90)
			cout << "Result " << resultNum << " is a B\n";

		if (score>=90)
			cout << "Result " << resultNum << " is a A\n";


		if(score!=-1)
		{
			sum=sum+score; //save inputs before continuing
			if (score>high)
			high = score; //check for high grades

			if (score<low)
			low = score; //check for low grades


			resultNum++; //used to divide average
			inputnum++;

			
		}
	}while (score !=-1);


	void letter(); //recieve grade

	//calc_average function for beautiful clean code

	cout << "The Average of the results = " << calc_average(sum,resultNum) << endl;
	cout << "The Lowest of the results = " << low << endl; 
	cout << "The Highest of the results = " << high << endl;

} 

float calc_average(float sum, int num)
{
	return (sum/num);
}

Edited 5 Years Ago by chuyauchi: n/a

sorry man , but where the array at? i can't see it man, please reexamine your code

for information, arrays are usually declared like this
{
int calculus [2];
// proceed to assign values to the array as follows
calculus [0]=45;
calculus [1]=23;
}
that should give you the basics of an array, goodluck then

for information, arrays are usually declared like this
{
int calculus [2];
// proceed to assign values to the array as follows
calculus [0]=45;
calculus [1]=23;
}
that should give you the basics of an array, goodluck then

#include <iostream>
#include <iomanip>
using namespace std;

float calc_average(float sum, int num);
void letter(float score, int resultNum);



float score[];
int resultNum = 0;
int inputnum = 1; // for visual appeal
float avg = 0;
long sum = 0;
float high = 0;
float low = 100;

// Function prototype
void letter(float score, int resultNum); //recieve grade
void print_display(float score, int inputnum);

int main()
{
	do
	{
		cout << "Enter result " << inputnum << " (or -1 if no more results) ";
		cin >> score[inputnum];

		if(score[inputnum] !=-1)
		{
			sum=sum+score[inputnum]; //save inputs before continuing
			if (score[inputnum]>high)
				high = score[inputnum]; //check for high grades

			if (score[inputnum]<low)
				low = score[inputnum]; //check for low grades

			resultNum++; //used to divide average
			inputnum++;

			letter(score[inputnum], resultNum); //recieve grade
			print_display(score[inputnum], inputnum);
		}
	}while (score[inputnum] !=-1);




	//calc_average function for beautiful clean code
	cout << "The Average of the results = " << calc_average(sum,resultNum) << endl;
	cout << "The Lowest of the results = " << low << endl; 
	cout << "The Highest of the results = " << high << endl;
} 


float calc_average(float sum, int num)
{
	return (sum/num);
}

void letter(float score, int resultNum)
{
	if (score<60)
		cout << "Result " << resultNum << " is a U\n";
		
	if (score>=60 && score<70)
		cout << "Result " << resultNum << " is a C\n";

	if (score>=70 && score<90)
		cout << "Result " << resultNum << " is a B\n";

	if (score>=90)
		cout << "Result " << resultNum << " is a A\n";
}

void print_display(float score, int inputnum)
{
	cout << "The list of the results and grades is:" << endl;
	for (int index = 0; index < 10; index++)
	{	
		cout << "Result " << (inputnum + 1) << ": " << score << endl;
	}
}

Here is the code what i'm trying to use array for scores.
I also need to make the LETTER GRADE into array but I don't know how to do it.

Edited 5 Years Ago by chuyauchi: n/a

Here is so far I have done. Could anyone tell me how to do the display?

#include <iostream>
#include <iomanip>
using namespace std;

double calc_average(double sum, double num);
void letter(double score, double resultNum);

double score[10];
double resultNum = 0;
int i = 1; // for visual appeal
double avg = 0;
double sum = 0;
double high = 0;
double low = 100;

// Function prototype

void letter(double score, double resultNum, char grade); //recieve grade


char grade[10];// Class Grade

double jjj;

int main()
{
	do
	{
		cout << "Enter result " << i << " (or -1 if no more results) ";
		cin >> score[i];
		jjj = score[i];
		if(score[i]!=-1)
		{
			sum=sum+jjj; //save inputs before continuing
			if (jjj>high)
				high = jjj; //check for high grades

			if (jjj<low)
				low = jjj; //check for low grades

			resultNum++; //used to divide average
			i++;

			letter(score[i], resultNum, grade[i]); //recieve grade
		}
	}while (score[i] !=-1);

	////////////////////////////////////////////////////////



	for ( i = 0; i < 10; i++)

		cout << score[i] << "\t" << grade[i] << endl;

	//////////////////////////////////////////////////////////

	//calc_average function for beautiful clean code
	cout << "The Average of the results = " << calc_average(sum,resultNum) << endl;
	cout << "The Lowest of the results = " << low << endl; 
	cout << "The Highest of the results = " << high << endl;


} 

double calc_average(double sum, double num)
{
	return (sum/num);
}

void letter(double score, double resultNum, char grade)
{
	if (score<60)
	{
		cout << "Result " << resultNum << " is a U\n";
		grade = 'U';
	}
	if (score>=60 && score<70)
	{
		cout << "Result " << resultNum << " is a C\n";
		grade = 'C';
	}
	if (score>=70 && score<90)
	{
		cout << "Result " << resultNum << " is a B\n";
		grade = 'B';
	}
	if (score>=90)
	{
		cout << "Result " << resultNum << " is a A\n";
			grade = 'A';
	}
}

Edited 5 Years Ago by chuyauchi: n/a

This question has already been answered. Start a new discussion instead.