Answer to Question #4814 in C++ for Suzy

Question #4814
my average keeps coming up 1%
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;


void avg (int testScore[], int testNum) // declare average function, testNum = for number of tests
{
double index = 0; //integer for index to do the for loop
double avg;
double total = 0; // zero out

for (index = 0; index < testNum; index++); // loop
{
total += testScore[testNum];

}

avg = total / testScore[testNum];

cout << "Your current average on " << testNum << " tests is " << avg << "% " << endl;

};

int _tmain(int argc, _TCHAR* argv[])

{

const int SZ = 5; //constant integer for the array//
int testScore[SZ]; //array to hold test scores//
int testNum;// integer for number of tests
int index; //counter
int sub = 0;
testNum = 0;

while (sub == 0)
{
cout<< "What is Number of tests you have taken in this course<1 through 5> : "; //number of tests input statement//
cin >> testNum;

if(testNum < 1 || testNum > SZ) // check to make sure test number value is valid
{
cout <<" Invalid Entry! please try again" << endl;
}
else
sub = 1;
}
for(index = 0; index < testNum; index++) // collect test scores using counter
{
cout << "Enter in the score you received on test " << index+1 << " : " ;
cin >> testScore[index];
}

avg (testScore, testNum); // call function

system ("pause.exe"); //pause to enable view of output//
return 0;
}
1
Expert's answer
2011-10-21T09:53:44-0400
Dear Suzy
Please give more detailes. What should be done in the programm? Should the programm calculate average?

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS