### calculater for a grade

I can't seem to get the formula right in the loop to add together all of the points total and points possible, and get a grade from them. Here is the question.

USE A FOR LOOP: At the beginning of the program you will ask the user their name and the number of programs that the student has done. Each program is worth a different amount. You will need to ask for the points made and the points possible for each. Use a loop to input and sum both sets of points. Print out the name and the program average in the following format:

// Preprocessor directives:

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

// Named constant definitions (and function declarations):

// Main program:

int main()
{
// Variable declarations:
string fname, lname;
int count, programs;
float possible, points;

// Function body:

cout << "Please enter your first name." <<endl;
cin >> fname;
cout << "Please enter your last name. " <<endl;
cin >> lname;
cout << "Please enter the number of programs you have completed. " <<endl;
cin >>programs;

for (int i = 1; i <= programs; i++)
{
cout<< "Enter the total points possible on the first program. "<<endl;
cin>> possible;
cout<< "Enter the points you made on the that program. "<<endl;
cin>>points;
grade = (possible
}

return 0;
} // end function main
You haven't finished the program yet. Your code wont work because at the end, you dont have equation for grade calculated. Also, you need to change the phrasing in your foo loop,
cout<<"enter the total points possible on the" << i <<"program"<<endl;
otherwise for you will get "possible for the first program" regardless of the amount of programs you've inputted. also, you need to make sure you multiply the 'grade' variable by 100, that equates to a percentage.
Okay, i understand what you're saying and I've gotten it work semi-good. But I need to be able to ask the user to enter how many tests that they have and I need to be able to ask how much each was worth and ask how many points they scored on each programs separately. I've gotten it to work with multiple ones, but my equation only takes into account the last score they entered in. I need it to add up the points they made and divide it by the total points possible for all tests. (Each test they enter is supposed to be of different value) I just need help with the equation. So here is what I have now....

// Preprocessor directives:

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

// Named constant definitions (and function declarations):

// Main program:

int main()
{
// Variable declarations:
string fname, lname;
int count, programs;
float possible, points, grade;

// Function body:

cout << "Please enter your first name." <<endl;
cin >> fname;
cout << "Please enter your last name. " <<endl;
cin >> lname;
cout << "Please enter the number of programs you have completed. " <<endl;
cin >>programs;

for (int i = 1; i <= programs; i++)
{
cout<< "Enter the total points possible on the "<<i<<" program. "<<endl;
cin>> possible;
cout<< "Enter the points you made on the "<<i<<" program. "<<endl;
cin>>points;
}

grade = (points / possible) * 100;

cout<< fname << " "<< lname << " grade is " << grade << endl;

return 0;
} // end function main
Last edited on
First, you need to edit your post so it uses code tags - the <> button on the right
Next, you need to store the input into an array, otherwise you will only have the last value entered.

There is no need to start at 1, the idiom for doing something 5 times is:

 ``1234`` ``````for(int a = 0; a < 5; a++) { //your code here }``````

The loop ends when `a < 5` becomes false.

Starting at zero is important because arrays start at zero.

Don't for get the code tags

HTH

Look in the reference / documentation section at the top left of this page.
Topic archived. No new replies allowed.