GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 04-Nov-2004, 22:39
Krc784 Krc784 is offline
New Member
 
Join Date: Nov 2004
Posts: 9
Krc784 is on a distinguished road

Small problem


This is my program i just wrote for class and i am having a slite problem on the first part of the output b/c it will ask me to enter the first number and when i enter it, it will automatically say that it is a invalid grade input and im not too sure why it does it b/c it will only do it on the first persons grades....please help if yall could.....thanks




CPP / C++ / C Code:
// Kevin Covington
// Lab 7

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

float calculation(float grades[], int);

int main()

{
	char name[5][2];
	char letter[6] = {'A', 'B', 'C', 'D', 'F', '\0'};
	const int numStudents = 5;
	const int numScores = 4;
	float total = 0;
	float average;
	float scores1[numScores];
	float scores2[numScores];
	float scores3[numScores];
	float scores4[numScores];
	float scores5[numScores];
	int count;

	// First student

	cout <<"Enter the test scores for the first student" << endl;
	for (int count = 0; count < numScores; count++)
	{
		cout << "The grade is " << (count+1) << ": ";
		cin >> scores1[count];
		while (scores1[count] < 0 || scores1[count] > 100);
		{
			cout << scores1[count] << " is invalid grade.\n";
			cout << "Enter the grade again. \n";
			cin >> scores1[count];
		}
	}
	average = calculation(scores1, numScores);
		if (average >= 90)
		{
			cout << "The average is " << average << " " << letter[0] << endl;
		}
		else if (average >= 80)
		{
			cout << "The average is " << average << " " << letter[1] << endl;
		}
		else if (average >= 70)
		{
			cout << "The average is " << average << " " << letter[3] << endl;
		}
		else if (average >= 60)
		{
			cout << "The average is " << average << " " << letter[4] << endl;
		}
		else 
		{
			cout << "The average is " << average << " " << letter[5] << endl;
		}

		// second student

	cout <<"Enter the test scores for the second student" << endl;
	for (int count = 0; count < numScores; count++)
	{
		cout << "The grade is " << (count+1) << ": ";
		cin >> scores2[count];
		while (scores2[count] < 0 || scores2[count] > 100)
		{
			cout << scores2[count] << " is invalid grade.\n";
			cout << "Enter the grade again. \n";
			cin >> scores2[count];
		}
	}
	average = calculation(scores2, numScores);
	if (average >= 90)
		{
			cout << "The average is " << average << " " << letter[0] << endl;
		}
		else if (average >= 80)
		{
			cout << "The average is " << average << " " << letter[1] << endl;
		}
		else if (average >= 70)
		{
			cout << "The average is " << average << " " << letter[3] << endl;
		}
		else if (average >= 60)
		{
			cout << "The average is " << average << " " << letter[4] << endl;
		}
		else 
		{
			cout << "The average is " << average << " " << letter[5] << endl;
		}

		// Third student

		cout <<"Enter the test scores for the third student" << endl;
	for (int count = 0; count < numScores; count++)
	{
		cout << "The grade is " << (count+1) << ": ";
		cin >> scores3[count];
		while (scores3[count] < 0 || scores3[count] > 100)
		{
			cout << scores3[count] << " is invalid grade.\n";
			cout << "Enter the grade again. \n";
			cin >> scores3[count];
		}
	}
	average = calculation(scores3, numScores);
	if (average >= 90)
		{
			cout << "The average is " << average << " " << letter[0] << endl;
		}
		else if (average >= 80)
		{
			cout << "The average is " << average << " " << letter[1] << endl;
		}
		else if (average >= 70)
		{
			cout << "The average is " << average << " " << letter[3] << endl;
		}
		else if (average >= 60)
		{
			cout << "The average is " << average << " " << letter[4] << endl;
		}
		else 
		{
			cout << "The average is " << average << " " << letter[5] << endl;
		}

		// Fourth Student

		cout <<"Enter the test scores for the fourth student" << endl;
	for (int count = 0; count < numScores; count++)
	{
		cout << "The grade is " << (count+1) << ": ";
		cin >> scores4[count];
		while (scores4[count] < 0 || scores2[count] > 100)
		{
			cout << scores4[count] << " is invalid grade.\n";
			cout << "Enter the grade again. \n";
			cin >> scores4[count];
		}
	}
	average = calculation(scores4, numScores);
	if (average >= 90)
		{
			cout << "The average is " << average << " " << letter[0] << endl;
		}
		else if (average >= 80)
		{
			cout << "The average is " << average << " " << letter[1] << endl;
		}
		else if (average >= 70)
		{
			cout << "The average is " << average << " " << letter[3] << endl;
		}
		else if (average >= 60)
		{
			cout << "The average is " << average << " " << letter[4] << endl;
		}
		else 
		{
			cout << "The average is " << average << " " << letter[5] << endl;
		}

		// Fifth student

		cout <<"Enter the test scores for the fifth student" << endl;
	for (int count = 0; count < numScores; count++)
	{
		cout << "The grade is " << (count+1) << ": ";
		cin >> scores5[count];
		while (scores5[count] < 0 || scores2[count] > 100)
		{
			cout << scores5[count] << " is invalid grade.\n";
			cout << "Enter the grade again. \n";
			cin >> scores5[count];
		}
	}
	average = calculation(scores5, numScores);
	if (average >= 90)
		{
			cout << "The average is " << average << " " << letter[0] << endl;
		}
		else if (average >= 80)
		{
			cout << "The average is " << average << " " << letter[1] << endl;
		}
		else if (average >= 70)
		{
			cout << "The average is " << average << " " << letter[3] << endl;
		}
		else if (average >= 60)
		{
			cout << "The average is " << average << " " << letter[4] << endl;
		}
		else 
		{
			cout << "The average is " << average << " " << letter[5] << endl;
		}
			

// }
// cout << endl;
return 0;
}

		float calculation (float grades[], int num)
		{
			float total = 0, average;
			for (int count = 0; count < num; count++)
				total += grades[count];
			
			average = total / num;
			cout << fixed << showpoint << setprecision(2);
			cout << "The total is " << total << endl;

			return average;
		}
		
			
		

	
  #2  
Old 05-Nov-2004, 08:34
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,710
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by Krc784
This is my program i just wrote for class and i am having a slite problem


Look at this:

CPP / C++ / C Code:
  for (int count = 0; count < numScores; count++)
  {
    cout << "The grade is " << (count+1) << ": ";
    cin >> scores1[count];
    while (scores1[count] < 0 || scores1[count] > 100); // <--- the semi-colon shouldn't be here
    {
      cout << scores1[count] << " is invalid grade.\n";
      cout << "Enter the grade again. \n";
      cin >> scores1[count];
    }
  }

This should get you a little farther along.

Regards,

Dave
 
 

Recent GIDBlogMeeting the local Iraqis by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Having a small problem with this program Krc784 C++ Forum 1 04-Nov-2004 22:25
Small Broadband Network Problem janey Computer Hardware Forum 3 24-Sep-2004 12:05
C I/O problem kelly80 C Programming Language 4 27-Apr-2004 20:15
Another FX 5600 problem (but with details that might shed light on this) BobDaDuck Computer Hardware Forum 2 16-Apr-2004 07:53
problem with php5 cgi installation fab13 Apache Web Server Forum 3 19-Nov-2003 09:11

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:39.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.