Article View: alt.comp.lang.learn.c-c++
Article #99Re: Problematic Program
From: CM
Date: Sun, 20 Oct 2002 21:43
Date: Sun, 20 Oct 2002 21:43
143 lines
5038 bytes
5038 bytes
--
CM
"Neil Butterworth" <neil_butterworth@lineone.net> wrote in message
news:3db31a56$1_1@mk-nntp-1.news.uk.worldonline.com...
>
> "CM" <mckenzie992@comcast.net> wrote in message
> news:ESudnc40b4i4hS6gXTWcow@comcast.com...
> > Hello everyone,
> > I thought I had finished a c++ V2
>
> What does "V2" mean?
>
> > program when I ended up having several
> > unexpected compilation errors that I am not sure how to fix.
>
> All compilation errors are unexpected.
>
> The jist of
> > the program is to take 5 student names, 5 ids for those students, 3
grades
> > for each student and then calculate gpa displaying in a table format:
> > Name Name 1 Name 2
> > Id 999 222
> > Grade 1 90 80
> > Grade 2 90 80
> > Grade 3
> > GPA
> > etc.
> >
> > I have included what I have so far, was hoping someone could help to
find
> my
> > mistake.
> > #include <string>
> > #include <iostream>
> > using namespace std;
> > #include <stdlib.h>
> > void main()
> > {
> > int noOfGrades=3;
> > int noOfStudents=5;
> > char names[noOfStudents]; // array of names (strings)
> > char ID[noOfStudents]; // array of ID's (strings)
> > double Grades[noOfStudents][noOfGrades]; // array of 5 arrays each of 3
>
> Your basic problem is here - the dimensions of automatic arrays in C++
must
> be constants known at compile time. One way of fixing your code would be
to
> declare your dimension sizes as:
>
> const int noOfGrades=3;
> const int noOfStudents=5;
>
> This will fix some, but not all. problems in your code. Patch these fixes
> in, try to fix the remaining problems and if you can't post here again.
But
> remember, we don't do homework for you.
>
> NeilB
I didn't copy over the correct instance .. here is the runtime error.
#include <string>
#include <iostream>
using namespace std;
#include <stdlib.h>
void main()
{
const int noOfGrades=3;
const int noOfStudents=5;
char names[noOfStudents]; // array of names (strings)
char ID[noOfStudents]; // array of ID's (strings)
double Grades[noOfStudents][noOfGrades]; // array of 5 arrays each of 3
//elements (each student has 3 double grades)
double GPA[5]; // array of gpa's (doubles)
float points;
int i,j;
for (i=0;i<noOfStudents;i++)
{
j=0;
points=0;
cout<<"Enter information for Student #"<<i+1<<":"<<endl;
cout<<"\tName: ";
//cin.getline(names[20],[i]);
cin>>names[i];
cout<<"\n\tID: ";
//cin.getline(ID[i],5);
cin>>ID[i];
for (j=0;j<noOfGrades;j++)
{
cout<<"\t\nGrade #"<<j+1<<": ";
cin>>Grades[i][j];
if (Grades[i][j] >= 0 && Grades[i][j] <= 59)
points+=0;
if (Grades[i][j] >= 60 && Grades[i][j] <= 64)
points+=1.0;
if (Grades[i][j] >= 65 && Grades[i][j] <= 69)
points+=1.5;
if (Grades[i][j] >= 70 && Grades[i][j] <= 74)
points+=2.0;
if (Grades[i][j] >= 75 && Grades[i][j] <= 79)
points+=2.5;
if (Grades[i][j] >= 80 && Grades[i][j] <= 84)
points+=3.0;
if (Grades[i][j] >= 85 && Grades[i][j] <= 89)
points+=3.5;
else
points+=4.0;
}
GPA[i]=points/noOfGrades;
}
cout<<"\nName\t";
for (i=0;i<noOfStudents;i++)
{
cout<<"\t"<<names[i];
}
cout<<"\nID\t";
for (i=0;i<noOfStudents;i++)
{
cout<<"\t"<<ID[i];
}
for (j=0;j<noOfGrades;j++)
{
cout<<"\nGrade #"<<j+1<<"\t";
for (i=0;i<noOfStudents;i++)
{
cout<<"\t"<<Grades[i][j];
}
}
cout<<"\nGPA\t";
for (i=0;i<noOfStudents;i++)
{
cout<<"\t"<<GPA[i];
}
}
Technical Details
Message-ID:
<BR2cndXHZoH7vi6gXTWcqg@comcast.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!ra.nrl.navy.mil!dca6-feed2.news.algx.net!dfw3-feed1.news.algx.net!allegiance!newsfeed.news2me.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!nntp3.aus1.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mailReferences:
<ESudnc40b4i4hS6gXTWcow@comcast.com> <3db31a56$1_1@mk-nntp-1.news.uk.worldonline.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,635d58b7486c58ea X-Google-Attributes: gid109fba,public X-Google-Thread: 114592,635d58b7486c58ea X-Google-Attributes: gid114592,public X-Google-Thread: 10d4ba,635d58b7486c58ea X-Google-Attributes: gid10d4ba,public X-Google-ArrivalTime: 2002-10-20 14:43:04 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!ra.nrl.navy.mil!dca6-feed2.news.algx.net!dfw3-feed1.news.algx.net!allegiance!newsfeed.news2me.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!nntp3.aus1.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Sun, 20 Oct 2002 16:43:02 -0500 From: "CM" <mckenzie992@comcast.net> Newsgroups: alt.comp.lang.learn.c-c++,att.lang.c++,comp.lang.c++ References: <ESudnc40b4i4hS6gXTWcow@comcast.com> <3db31a56$1_1@mk-nntp-1.news.uk.worldonline.com> Subject: Re: Problematic Program Date: Sun, 20 Oct 2002 17:43:03 -0400 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Message-ID: <BR2cndXHZoH7vi6gXTWcqg@comcast.com> Lines: 145 X-Trace: sv3-PjjHVjdEAL17Pv070JvKiHIpmfAXDx/r8GzDB0IP8xGyU6B5GXSrzI2ts1+ST0I/4OSOGr/IVLp098/!Mkq1LwaB6dyUDPeP5DVEcRO0CLp1XZoILA+z4MRkzkI9YyImqX0ifIn5+x4= X-Complaints-To: abuse@comcast.com X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.1