C++ for loop and percentage help

I tried writing code for this question but i always getting this error. please let me know what i am doing wrong. here is question, code, and the error.

Write a program that calculates the total grade for N classroom exercises as a percentage. The user to input the value for N followed by each of the N scores and totals. Calculate the overall percentage (sum of the total points earned divided by the total point possible) and output it as a percentage. Sample input and output it as a percentage. Sample input and output is shown below.
How many exercises to input?
score1: 10
total points possible: 10
score2: 7
total points possible: 12
score3: 5
total points possible: 8

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# include <iostream>
using namespace std;
int main ()
{
double N=0, score, total, totalScore=0, totalGrade=0, GRADE;

cout<<"How many excersices will be scored?/n";
cin>>N;

for(int n=1; n>N ; n++)
{
cout<<"Enter score # "<<n<<"/n";
cin>>score;
cout<<"Enter the max total for score # "<<n<<"/n";
cin>>total;

totalScore = totalScore + score;
totalGrade = totalGrade + total;
}

GRADE = (totalScore/totalGrade)*100;
cout<<"Your total is "<<totalScore<<" out of "<<totalGrade<<" /n";
cout<<", or "<<GRADE<<"%./n";


return 0;
}

error:
1>------ Build started: Project: HOMEWORK5, Configuration: Debug Win32 ------
1>LINK : error LNK2001: unresolved external symbol _mainCRTStartup
1>C:\Users\WORK\HOMEWORK5\Debug\HOMEWO… : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
If that is the full log, it would appear that the source file you reproduced for us has not been added to your project.
You have your for loop executing incorrectly. It is best to name variables that the program uses to something more useful. Change N to something like numOfExercises.

You have this:

1
2
3
4
for (int n=1; n > N; n++)
{
     //Work here
}


It should be:
1
2
3
4
for (int n=1; N > n; n++)
{
     //Work here
}


Your program is executing, but the for loop is always evaluating to false, because even if you wanted to input exactly 1 grade, the for loop would execute to false. You want to compare your incremented variable "n" with the total number of exercises "N".
It should be:
1
2
3
4
for (int n=1; N > n; n++)
{
     //Work here
}


N is 0. What you've done is to accomplish exactly what you said you were trying to cure.

The program is not executing, because the linker is failing.

N is 0. What you've done is to accomplish exactly what you said you were trying to cure.

The program is not executing, because the linker is failing.


Did you even look at the OP's code?

N represents the number of exercises that are going to be entered as grades. For example, I want to submit 10 scores, so I would input 10 for N. Therefore, what you are saying is that going through a loop, the first evaluation would be 1 > 10, which is false.

N is only 0 by default, and is not 0 when it receives user input.

It should be as I said.

EDIT: when you set up your incrementing variable n, it should be int n = 0; not n = 1, because if you wanted to input exactly 1 grade, your loop would not execute because 1 !> 1
Last edited on
Topic archived. No new replies allowed.