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 31-May-2004, 12:17
homz homz is offline
New Member
 
Join Date: May 2004
Location: ohio
Posts: 23
homz is on a distinguished road

C++ problem


Hello need help with solving this c++ program.... for some reason it does not pause the program so i am not sure if i have done everything correctly or not???? or it needs to be written differently... appreciate all the help....thanks
OOOpppps i forgot to include the problem...lol... ok here is what i had to do....
had to write a program that read a file consisting of students test scores in the range of 0-200. It then had to determine the number of students having scores in each of the following ranges:0-24, 25-49, 50-74, 75-99, 100-124, 125-149, 150-174, and 175-200. Output the score ranges and the number of students.(run your program with the following input data:76,89,150,135,200,76,12,100,150,28,178,189,16 7,200,175,150,87,99,129,149,176,200,87,35,157,189)
[c]
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

const int maxCategory=7;
int getCategory(int);
void initialize(int student[]);
void getStudent(int category, int student[]);
void printArray(int category, int student[]);

int main()
{
int category;
int score;
int student[maxCategory];
ifstream infile;
infile.open("score.txt");

if (!infile)
{
cout<<"Cannot open input file. "<< endl;
return 1;
}

initialize(student);
infile>>score;

while (!infile.eof())
{
category = getCategory(score);
getStudent(category, student);

infile>>score;
}

infile.close();
printArray(category, student);

system("Pause");
return 0;
}

void initialize(int student[])
{
int j;
for (j=0;j<=maxCategory;j++)
{
student[j]=0;
}
}

void getStudent(int c, int s[])
{
if (c<=maxCategory)
{
s
CPP / C++ / C Code:
++;      
	}
}

void printArray(int category, int student[])
{
	string scoreRange;
	cout<<"Score Range"<<"          ";
	cout<<"Number of Student"<<endl;

	for (category=0; category<=maxCategory;category++)
	  {
		  switch (category)
		  {
		  case 0:
			  scoreRange= "0-24";
			  break;
                            case 1:
			  scoreRange= "25-49";
			  break;
	               case 2:
			  scoreRange= "50-74";
			  break;
		  case 3:
			  scoreRange= "75-99";
	                            break;	                                                                                                                       case 4:
			  scoreRange= "100-124";
			  break;
		  case 5:
			  scoreRange= "125-149";
			  break;
		  case 6:
			  scoreRange= "150-174";
			  break;
		  case 7:
			  scoreRange= "175-200";
			  break;
		  }

	     cout<< scoreRange<<"                 ";
	      cout <<student[category]<<endl;	  
      }
}

int getCategory(int score)
{
    int scoreRange;

    if (score >=0 && score <25)
	scoreRange=0;
	
   else if (score >=25 && score <50)
	scoreRange=1;
	
   else if (score >=50 && score <75)
	scoreRange=2;

   else if (score >=75 && score < 100)
	scoreRange=3;

   else if (score >=100 && score <125)
	scoreRange=4;

   else if (score >=125 && score <150)
	scoreRange=5;

   else if (score >=150 && score <175)
	scoreRange=6;

   else if (score >=175 && score <=200)
	scoreRange=7;

   else
     cout<<"Invalid score";

     return scoreRange;
}
  #2  
Old 31-May-2004, 20:21
Max Payne's Avatar
Max Payne Max Payne is offline
Regular Member
 
Join Date: Apr 2004
Location: 3° 08 North 101° 42 East
Posts: 332
Max Payne is a jewel in the roughMax Payne is a jewel in the roughMax Payne is a jewel in the rough
Whats the problem, It works fine with me!? the pause works fine,,,
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds
  #3  
Old 01-Jun-2004, 00:56
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Same here...
__________________
-Aaron
  #4  
Old 01-Jun-2004, 09:07
homz homz is offline
New Member
 
Join Date: May 2004
Location: ohio
Posts: 23
homz is on a distinguished road

help


Well it does not work for me....I use dev C++.... and also could you please tell me if i need to change anything.... thanks

Quote:
Originally Posted by Max Payne
Whats the problem, It works fine with me!? the pause works fine,,,
  #5  
Old 01-Jun-2004, 11:35
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Your getStudent function is a bit cryptic, and the name does not describe its purpose at all. I would definitely change the name of that function to reflect what it does.
__________________
-Aaron
 
 

Recent GIDBlogWriting a book 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
C I/O problem kelly80 C Programming Language 4 27-Apr-2004 21:15
Another FX 5600 problem (but with details that might shed light on this) BobDaDuck Computer Hardware Forum 2 16-Apr-2004 08:53
problem with php5 cgi installation fab13 Apache Web Server Forum 3 19-Nov-2003 10:11
unwanted scrollbar problem kelly001 Web Design Forum 3 24-Oct-2003 11:44
A problem Between MySQL <> phpBB mirable MySQL / PHP Forum 3 10-Sep-2003 06:31

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

All times are GMT -6. The time now is 01:58.


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