Hello all,

I am completely new to c++ and have no idea what am doing or should be doing but am ready to learn. My first problem is to write a code "to calculate average score of uncertain numbers of student and the output should be (number of students,total points and average)".

This is what i have so far, have been on this for over 12hrs and i just don't know what to do anymore - any help will be greatly appreciated.

Thank-you much.
Effizy.

``````#include <iostream>

using namespace std;

int count, score;
float average=0.0;
count=0
int numTimesNeeded = [];
int total=0;
while ( count < numTimesNeeded )

int main()
{
cout <<"***************** Score Calculator 1.0 *****************"<<endl;
cout <<"Welcome!"<< endl;
cout <<"This program computes the average score of students"<<endl;
cout <<"You supply the data on: the number of students and score for each student"<<endl;
cout <<"The program will compute the total and average score for you."<<endl;
cout <<"**********************************************************"<< endl;
cout <<"Let's get to work ..." << endl;
cout <<"Enter the score for test " << count + 1 << ": ";
cin >> score;
total += score;
count++;
{
average = float(total) / numTimesNeeded;
cout <<"The average of the " << numTimesNeeded << " test scores is:" << average <<   endl;

}

system("PAUSE");
return 0;
}``````
2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by bleedi

There's quite a few problems there.

``````int count, score;
float average=0.0;
count=0
int numTimesNeeded = [];
int total=0;
while ( count < numTimesNeeded )``````

These shouldn't be outside main(). Every line of code should end with ';', and - as you might notice - the line with "count=0" should be "count=0;".

Do you have an idea how to use "while"-loops? Your way isn't right at all, let me demonstrate:

``````int main() {
int num_students = 0;
double total = 0.0;
double avg = 0.0;
double tempscore = 0.0;

while(tempscore != -1) {
cout << "Give a score (-1 will quit): " << endl;
cin >> tempscore;
if(tempscore != -1) {
total += tempscore;
++num_students;
avg = total / num_students;
}
}

cout << "Average score is: " << avg << endl;

return 0;
}``````

Edited by bleedi: n/a

Thanks alot Bleedi,very grateful for the response.Per your question - NO i do not know how to use while loop or what it means for that matter, this is my first ever encounter with C++. Its all completely new to me. What you see here is just a figment of my own imagination - didn't wanna show up here without any effort from my end. What should my train of thought be exactly on this problem?

Well, I suggest you start checking out all the things you have a slightest concern not knowing or understanding about. Start by studying the basic concepts of program structures, then going more in-depth to understand different loops (while, do-while, for) etc.

I know there's just tons of things to learn, and when starting programming, it's hard to understand the relevant things of the beginning. I suggest googling for some introductionary material into C++ and general programming.

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.