#include <iostream>
#include <iomanip>
#include <cstring>
#include <cmath>
using namespace std;
int main()
{ bool more_students;
char choice, name, lgrade;
double average;
int totstudents;
// Check to see if there are any students.
cout << " Are there any students? <Y> or <N> \n";
cin >> choice;
more_students = (choice == 'N' || choice == 'n')
break;
more_students = more_students + 1;
totstudents += more_students;
cout << " Enter Last and First name : ";
cin >> name;
// Enter and Calculate grade.
int grade[4];
int temp;
for( int g=0; g<4; g++)
{
cout << " Enter grade: " << g + 1 << endl;
cin >> grade[g];
}
// Find the average.
int sum = 0;
// double average;
for( int f=0; f<4; f++)
sum += grade[f];
average = sum / 4.0;
for( int i=1; i<4; i++)
for( int k=0; k<4-i; k++)
{
if( grade[k] > grade[k+1] )
}
{ temp = grade[k];
grade[k] = grade[k+1];
grade[k+1] = temp;
}
if(( average <= 100) && ( average >= 0))
{
if(average >= 90)
lgrade = 'A';
else if(average >= 80)
lgrade = 'B';
else if(average >= 70)
lgrade = 'C';
else if(average >= 65)
lgrade = 'D';
else lgrade = 'F';
return lgrade;
}
{
cout << " Are there any more students? <Y> or <N> \n";
cin >> choice;
if(choice == 'N' || choice == 'n')
break;
for( int h=0; h<4; h++)
cout << name << setw(5) << grade[h] << setw(5) << average << setw(5) << lgrade;
cout << " There were " << totstudents << " students processed \n";
system("pause");
return 0;
}
Student Grades
Page 1 of 1
Student Grades Program needs to enter student names,show 4 grades entered,calculate a
#1
Posted 07 June 2009 - 12:28 PM
#3
Posted 07 June 2009 - 12:57 PM
AGRAC393, on 7 Jun, 2009 - 12:30 PM, said:
What have you tried?... What errors are you getting?
These are my errors:
In function `int main()':
Line 16 expected `;' before "break"
Line 40 expected primary-expression before '}' token
Line 40 expected `;' before '}' token
Line 41 `k' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
Line 62 break statement not within loop or switch
Line 69 expected `}' at end of input
#4
Posted 07 June 2009 - 01:23 PM
There should be a semicolon after this line:
I don't understand what the purpose of the break; statement is? At the time it is called, you are not in any sort of loop to break out of. That will cause an error.
This section is strange.
You need to take a look at your curly braces and figure out their correct placement. Also, your variable k is declared inside a for loop and then used outside of the for loop later on. This will cause an error as well.
more_students = (choice == 'N' || choice == 'n') //;
I don't understand what the purpose of the break; statement is? At the time it is called, you are not in any sort of loop to break out of. That will cause an error.
This section is strange.
// Find the average.
int sum = 0;
// double average;
for( int f=0; f<4; f++)
sum += grade[f];
average = sum / 4.0;
for( int i=1; i<4; i++)
for( int k=0; k<4-i; k++)
{
if( grade[k] > grade[k+1] )
}
You need to take a look at your curly braces and figure out their correct placement. Also, your variable k is declared inside a for loop and then used outside of the for loop later on. This will cause an error as well.
This post has been edited by apw5020: 07 June 2009 - 01:24 PM
#5
Posted 07 June 2009 - 04:33 PM
apw5020, on 7 Jun, 2009 - 01:23 PM, said:
There should be a semicolon after this line:
I don't understand what the purpose of the break; statement is? At the time it is called, you are not in any sort of loop to break out of. That will cause an error.
This section is strange.
You need to take a look at your curly braces and figure out their correct placement. Also, your variable k is declared inside a for loop and then used outside of the for loop later on. This will cause an error as well.
more_students = (choice == 'N' || choice == 'n') //;
I don't understand what the purpose of the break; statement is? At the time it is called, you are not in any sort of loop to break out of. That will cause an error.
This section is strange.
// Find the average.
int sum = 0;
// double average;
for( int f=0; f<4; f++)
sum += grade[f];
average = sum / 4.0;
for( int i=1; i<4; i++)
for( int k=0; k<4-i; k++)
{
if( grade[k] > grade[k+1] )
}
You need to take a look at your curly braces and figure out their correct placement. Also, your variable k is declared inside a for loop and then used outside of the for loop later on. This will cause an error as well.
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cmath>
using namespace std;
int main()
{
int grade[4];
int temp;
bool more_students;
char choice, name, lgrade;
int totstudents;
// Check to see if there are any students.
cout << " Are there any students? <Y> or <N> \n";
cin >> choice;
more_students = (choice == 'Y' || choice == 'y');
//break;
//more_students = more_students + 1;
//totstudents += more_students;
cout << " Enter Last and First name : ";
cin >> name;
// Enter and Calculate grade.
//int grade[4];
//int temp;
for( int g=0; g<4; g++)
{
cout << " Enter grade: " << g + 1 << endl;
cin >> grade[g];
}
// Find the average.
int sum = 0;
double average;
for( int k=0; k<4; k++)
sum += grade[k];
average = sum / 4.0;
for( int i=1; i<4; i++)
{ for( int m=0; m<4-i; m++)
if( grade[m] > grade[m+1] )
{ temp = grade[m];
grade[m] = grade[m+1];
grade[m+1] = temp;
}
}
if(( average <= 100) && ( average >= 0))
{
if(average >= 90)
lgrade = 'A';
else if(average >= 80)
lgrade = 'B';
else if(average >= 70)
lgrade = 'C';
else if(average >= 65)
lgrade = 'D';
else lgrade = 'F';
return lgrade;
}
cout << " Are there any more students? <Y> or <N> \n";
cin >> choice;
more_students = (choice == 'Y' || choice == 'y');
//break;
more_students = more_students + 1;
totstudents += more_students;
for( int h=0; h<4; h++)
cout << name << setw(5) << grade[h] << setw(5) << average << setw(5) << lgrade;
cout << " There were " << totstudents << " students processed \n";
system("pause");
return 0;
}
Quote
My output is not right. It looks like this:
Are there any students? <Y> or <N>
y
Enter Last and First name : mark smith
Enter grade: 1
Enter grade: 2
Enter grade: 3
Enter grade: 4
Are there any more students? <Y> or <N>
m 21.42746e+006 pm 441.42746e+006 pm 1761.42746e+006 pm57096081.4
2746e+006 p There were 1 students processed
Press any key to continue . . .
My output should let me enter the grades, display each grade entered, show the average, and tell how many students were processed.
Are there any students? <Y> or <N>
y
Enter Last and First name : mark smith
Enter grade: 1
Enter grade: 2
Enter grade: 3
Enter grade: 4
Are there any more students? <Y> or <N>
m 21.42746e+006 pm 441.42746e+006 pm 1761.42746e+006 pm57096081.4
2746e+006 p There were 1 students processed
Press any key to continue . . .
My output should let me enter the grades, display each grade entered, show the average, and tell how many students were processed.
#6
Posted 07 June 2009 - 05:18 PM
First thing is to follow the excellent advice of apw5020.
Go through your code line by line.
Remove commented out code.
Put the braces "{" "}" where they should be according to one of the two main styles. Choose one of them and apply it consistently.
Indent your code as per the bracing style you have chosen.
When your code is tidy you will probably see your mistakes straight away. If you can't, see them come back to us but you do need to do your own housekeeping before sharing your code with strangers and asking them to try and read it.
Here is your code in something approaching a readable form:
Now that we can see what is in there a couple of things jump out.
What is this intended to do?
And this?
Go through your code line by line.
Remove commented out code.
Put the braces "{" "}" where they should be according to one of the two main styles. Choose one of them and apply it consistently.
Indent your code as per the bracing style you have chosen.
When your code is tidy you will probably see your mistakes straight away. If you can't, see them come back to us but you do need to do your own housekeeping before sharing your code with strangers and asking them to try and read it.
Here is your code in something approaching a readable form:
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cmath>
using namespace std;
int main() {
int grade[4];
int temp;
bool more_students;
char choice, name, lgrade;
int totstudents;
// Check to see if there are any students.
cout << " Are there any students? <Y> or <N> \n";
cin >> choice;
more_students = (choice == 'Y' || choice == 'y');
cout << " Enter Last and First name : ";
cin >> name;
// Enter and Calculate grade.
for( int g=0; g<4; g++){
cout << " Enter grade: " << g + 1 << endl;
cin >> grade[g];
}
// Find the average.
int sum = 0;
double average;
for( int k=0; k<4; k++) {
sum += grade[k];
}
average = sum / 4.0;
for( int i=1; i<4; i++) {
for( int m=0; m<4-i; m++) {
if( grade[m] > grade[m+1] ) {
temp = grade[m];
grade[m] = grade[m+1];
grade[m+1] = temp;
}
}
if(( average <= 100) && ( average >= 0)) {
if(average >= 90) {
lgrade = 'A';
} else if(average >= 80) {
lgrade = 'B';
} else if(average >= 70) {
lgrade = 'C';
} else if(average >= 65) {
lgrade = 'D';
} else {
lgrade = 'F';
}
return lgrade;
}
cout << " Are there any more students? <Y> or <N> \n";
cin >> choice;
more_students = (choice == 'Y' || choice == 'y');
more_students = more_students + 1;
totstudents += more_students;
for( int h=0; h<4; h++) {
cout << name << setw(5) << grade[h] << setw(5)
<< average << setw(5) << lgrade;
}
cout << " There were " << totstudents << " students processed \n";
system("pause");
return 0;
}
Now that we can see what is in there a couple of things jump out.
What is this intended to do?
return lgrade;
And this?
more_students = (choice == 'Y' || choice == 'y');
more_students = more_students + 1;
This post has been edited by janotte: 07 June 2009 - 05:30 PM
#7
Posted 07 June 2009 - 05:55 PM
Dude i think you made this harder than it is
Does this help?
Kevin
think that percentage is wrong but ill let u sort that 3am here, off to bed
#include "stdafx.h"
#include <iostream>
#include <string>
#include "conio.h"
using namespace std;
int main()
{
float grade[4];
string name;
char lgrade;
int studentCount = 1;
cout << "\n\n\n"; // new lines
cout << " Enter Student name : ";
cin >> name;
cout << "\n\n";
cout << " Enter 1st grade: ";
cin >> grade[0];
cout << " Enter 2nd grade: ";
cin >> grade[1];
cout << " Enter 3rd grade: ";
cin >> grade[2];
cout << " Enter 4th grade: ";
cin >> grade[3];
// Find the average.
float sum;
float percentage;
sum = grade[0] + grade[1] + grade[2] + grade[3];
percentage = sum / 100;
// process results
if(percentage > 0.70)
{
lgrade = 'A';
}
else if((percentage > 0.60) && (percentage <= 0.70 ))
{
lgrade = 'B';
}
else if((percentage > 0.50) &&(percentage <= 0.60 ))
{
lgrade = 'C';
}
else if((percentage > 0.40) && (percentage <=0.50 ))
{
lgrade = 'D';
}
else
{
lgrade = 'F';
}
cout << "\n\n\n"; // new lines
cout << " Student Name : " << name << endl;
cout << " percentage : " << percentage << endl;
cout << " Grade : " << lgrade << endl;;
cout << " Total Students : " << studentCount;
_getch(); // waits for key press
return 0;
}
Does this help?
Kevin
think that percentage is wrong but ill let u sort that 3am here, off to bed
Page 1 of 1

Start a new topic
Add Reply




MultiQuote


| 


