# I have no idea how to store a character into an array

Page 1 of 1

## 2 Replies - 641 Views - Last Post: 07 October 2012 - 08:24 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=294560&amp;s=36fc441054915b8ddf93ccb001de1217&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 alexb9054

Reputation: 0
• Posts: 4
• Joined: 05-October 12

# I have no idea how to store a character into an array

Posted 06 October 2012 - 06:39 PM

Assignment Questions:

4. Calculate each student letter grade using a function, save the letter grade to another array defined in main function.
5. Return the count of the grades for each letter grade (A, B, C,D, F) using a function
6. Perform a selection sort on the number grade array into descending order and output them again using functions.

I need some help on the last 3 questions of my assignment and I cannot figure out how to do it. Here's my code so far. I just don't know how to save them in an array etc. The code worked perfect before I tried to get the letter grade code working. I have no idea how to do this. Could someone help me or even better give me an example of something similar and explain it. I've been stuck on this for the past 4 hours.

```#include <iostream>
#include <cmath>
#include <string>
#include <math.h>

using namespace std;
//Global Function
void averageMaxCalc(int scoreInput[5], int sumZ, double& sAverage, double& sAverageF);
void studentScoreCalc(int scoreInput[5], int sum);//Function studentScore()
void deviation(int scoreInput[5], int sum);

//|=======================|
//|======== Main =========|
//|=======================|
int main (char LetterDefined)
{
cout << "Welcome to the student score calculator program.\n\n";
//Variables
int scoreInput[5], sum = 0, sumZ = 0;
double sAverage, sAverageF;

//Defined
char letterDefined;
for (int m = 0; m < 6; ++m)
{
}

//Functions Within Main()
studentScoreCalc(scoreInput, sum);//Function StudentScore()
averageMaxCalc(scoreInput, sumZ, sAverage, sAverageF);//Function averageMaxCalc()
deviation(scoreInput, sum);//Function deviation()

system("pause");
return 0;

}
//|=====================================|
//|=== 1. Student Input and Max/Less ===|
//|=====================================|
void studentScoreCalc(int scoreInput[5], int sum)
{
//Declearing Variables
sum = 0;

cout << "Please Enter Student Scores below: \n";//Outputs to Console
//Sum is set to 0

//Looping countScore and i 15x
for (int i = 0; i <5; i++)
{
cin >> scoreInput[i];//Creates User Input

}
}

//|=================================|
//|=== 2. Funtion averageMaxCalc ===|
//|=================================|
void averageMaxCalc(int scoreInput[5], int sumZ, double& sAverage, double& sAverageF)
{
sumZ = 0;//Set sumZ to 0;

//Gets Sum Of All Numbers
sumZ = scoreInput[0]+scoreInput[1]+scoreInput[2]+scoreInput[3]+scoreInput[4];
//Finds The Average
sAverage = sumZ / 5;//Finds Average
sAverageF = (sumZ%5)*2;//Finds Decimal
cout << "The Sum Of All Scores Is: " <<sumZ << "\n"
<< "The Average Is: " << sAverage << "." << sAverageF << endl;
}
//|===================================|
//|=== 3. Calculation of Deviation ===|
//|===================================|
void deviation(int scoreInput[5], int sum)
{
double eX2Input;
double eXInput;
double variance;
double sDeviation;

//Gets EX^2
eX2Input = pow(scoreInput[0], 2) + pow(scoreInput[1], 2) + pow(scoreInput[2], 2) + pow(scoreInput[3], 2) + pow(scoreInput[4],2);
eXInput = scoreInput[0] + scoreInput[1] + scoreInput[2] + scoreInput[3] + scoreInput[4];
variance = (5*(eX2Input)-(eXInput))/(5 * (5-1));//Calculates Variance
sDeviation = sqrt(variance);//Calculates Standard Deviation
//Testing output
cout << "The Standard Deviation is: " << sDeviation << endl;
}
//|===============================================|
//|======= 4. Grades Converted To Letters ========|
//|===============================================|
{

if(scoreInput[0] <= 100)
scoreInput[0] = 'A';
else if(scoreInput[0] < 90)
scoreInput[0] = 'B';
else if(scoreInput[0] < 80)
scoreInput[0] = 'C';
else if(scoreInput[0] < 70)
scoreInput[0] = 'D';
else if(scoreInput[0] < 60)
scoreInput[0] = 'F';

if(scoreInput[1] <= 100)
scoreInput[1] = 'A';
else if(scoreInput[1] < 90)
scoreInput[1] = 'B';
else if(scoreInput[1] < 80)
scoreInput[1] = 'C';
else if(scoreInput[1] < 70)
scoreInput[1] = 'D';
else if(scoreInput[1] < 60)
scoreInput[1] = 'F';

if(scoreInput[2] <= 100)
scoreInput[2] = 'A';
else if(scoreInput[2] < 90)
scoreInput[2] = 'B';
else if(scoreInput[2] < 80)
scoreInput[2] = 'C';
else if(scoreInput[2] < 70)
scoreInput[2] = 'D';
else if(scoreInput[2] < 60)
scoreInput[2] = 'F';

if(scoreInput[3] <= 100)
scoreInput[3] = 'A';
else if(scoreInput[2] < 90)
scoreInput[3] = 'B';
else if(scoreInput[2] < 80)
scoreInput[3] = 'C';
else if(scoreInput[2] < 70)
scoreInput[3] = 'D';
else if(scoreInput[2] < 60)
scoreInput[3] = 'F';

if(scoreInput[4] <= 100)
scoreInput[4] = 'A';
else if(scoreInput[2] < 90)
scoreInput[4] = 'B';
else if(scoreInput[2] < 80)
scoreInput[4] = 'C';
else if(scoreInput[2] < 70)
scoreInput[4] = 'D';
else if(scoreInput[2] < 60)
scoreInput[4] = 'F';

char letterGrade[][6] = {'A', 'B', 'C', 'D', 'F'};

}
```

Is This A Good Question/Topic? 0

## Replies To: I have no idea how to store a character into an array

### #2 jimblumberg

Reputation: 4912
• Posts: 15,349
• Joined: 25-December 09

## Re: I have no idea how to store a character into an array

Posted 06 October 2012 - 08:17 PM

First main can only be defined as int main(), or int main(int argc, char **argv). Not int main (char LetterDefined).

Now after you fix that what exactly don't you understand about question 4?

Quote

4. Calculate each student letter grade using a function, save the letter grade to another array defined in main function.

Have you learned about loops yet? If so you may want to consider a loop in your letterGradesA() function. And you should not be calling this function in your return statement.

I suggest you study the links provided in my signature, they should help you with using functions.

Jim

### #3 alexb9054

Reputation: 0
• Posts: 4
• Joined: 05-October 12

## Re: I have no idea how to store a character into an array

Posted 07 October 2012 - 08:24 AM

I didn't think of using loops. Thanks