School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,125 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 4,057 people online right now. Registration is fast and FREE... Join Now!



Student Grades

Student Grades Program needs to enter student names,show 4 grades entered,calculate a Rate Topic: -----

#1 sigmafunk  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 6
  • Joined: 04-April 09


Dream Kudos: 0

Post icon  Posted 07 June 2009 - 12:28 PM

#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;
}


Was This Post Helpful? 0
  • +
  • -


#2 AGRAC393  Icon User is offline

  • D.I.C Head
  • PipPip
  • Group: Members
  • Posts: 240
  • Joined: 13-May 09


Dream Kudos: 25

Posted 07 June 2009 - 12:30 PM

What have you tried?... What errors are you getting?
Was This Post Helpful? 0
  • +
  • -

#3 sigmafunk  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 6
  • Joined: 04-April 09


Dream Kudos: 0

Posted 07 June 2009 - 12:57 PM

View PostAGRAC393, 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
Was This Post Helpful? 0
  • +
  • -

#4 apw5020  Icon User is offline

  • D.I.C Addict
  • PipPipPipPip
  • Group: Members
  • Posts: 585
  • Joined: 26-March 09


Dream Kudos: 0

Posted 07 June 2009 - 01:23 PM

There should be a semicolon after this line:
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

Was This Post Helpful? 0
  • +
  • -

#5 sigmafunk  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 6
  • Joined: 04-April 09


Dream Kudos: 0

Posted 07 June 2009 - 04:33 PM

View Postapw5020, on 7 Jun, 2009 - 01:23 PM, said:

There should be a semicolon after this line:
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.

Was This Post Helpful? 0
  • +
  • -

#6 janotte  Icon User is offline

  • code > sword
  • Icon
  • Group: Expert w/DIC++
  • Posts: 2,675
  • Joined: 28-September 06


Dream Kudos: 0

Expert In: C/C++

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:

#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

Was This Post Helpful? 0
  • +
  • -

#7 deery5000  Icon User is offline

  • D.I.C Regular
  • PipPipPip
  • Group: Members
  • Posts: 380
  • Joined: 09-May 09


Dream Kudos: 0

Posted 07 June 2009 - 05:55 PM

Dude i think you made this harder than it is

#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 :P
Was This Post Helpful? 0
  • +
  • -

#8 sigmafunk  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 6
  • Joined: 04-April 09


Dream Kudos: 0

Posted 07 June 2009 - 06:42 PM

View Postapw5020, on 7 Jun, 2009 - 01:23 PM, said:

I got everything to work. Thanks to everyone who helped me.

Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month