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 17-Dec-2005, 22:57
needcishelp needcishelp is offline
New Member
 
Join Date: Dec 2005
Posts: 13
needcishelp is on a distinguished road

In Need of Some Serious Help...compiling errors [C++]


So i've been working on this code, but i've been getin all sorts of errors, and can't for the life of me understand why. I'm pretty new to C++ so be gentle...haha

the program is meant to create a grade sheet for a bunch of students with input of grades and names etc...It should also calculate the average of the grades. Trying to compile it only shows lots of errors i can't quite figure out.
CPP / C++ / C Code:
//***********************Preprocessor Directives****************************
#include <fstream.h>
#include <iomanip.h>
#include <iostream.h>
#include <string.h>
#include <conio.h>
#include <math.h>

using namespace std;
//************************** main ******************************************
void main()
{
	const int		MAX_SIZE = 30;
					NAME_SIZE = 31;

	typedef char STRING_30[NAME_SIZE];
	typedef STRING_30 LIST_S30[MAX_SIZE];
	typedef int LIST_I[MAX_SIZE];

	int				num_students,		//array size
					loc_value,			//lcv/array index
					choice,
					credit;				//credits recieved for the class
	char			drive[2],
					disk_file[15],
					file[9],
					course[20],			//course name
					semester[15],			
					professor_name[25];
	LIST_I			average,			//average of midterm, final and project grades
					midterm_grade,		
					final_grade,
					project;
	LIST_S30		student_name,
					overall_grade;
	ofstream		outfile;


																					//input section
cout << "Enter Professor Name: ";
cin >> ws;
cin.getline (professor_name,(sizeof(professor_name)-1));
cout << "Semester: " ;
cin >> ws;
cin.getline (semester,(sizeof(semester) -1));
cout << "Course Name: ";
cin >> ws;
cin.getline (course,(sizeof(course)-1));
cout << "Number of Credits: ";
cin >> credit;

if (credit < 1 || credit > 6)
	cout << "Enter Number of Credits (1-6): ";

do { 
	cout << "Enter the Number of Students: ";
	cin >> num_students;
	}
while (num_students > 0 && num_students <= 30);
{	for (loc_value = 0; loc_value <= num_students; loc_value++)
	cout << "Enter Student Name: ";
	cin >> ws;
	cin.getline(student_name[loc_value], (sizeof (student_name[loc_value])-1));
	cout << "Enter Midterm Grade: ";
	cin >> midterm_grade[loc_value];
	cout << "Enter Final Grade: ";
	cin >> final_grade[loc_value];
	cout << "Enter Project Grade: ";
	cin >> project[loc_value];
}

																					//process section
//the following is to calculate the average
average = ((2 * midterm_grade) + (3 * final_grade) + project) / 6;
//the following is supposed to make a letter grade once the average is //discovered
if (average >= 90)
	overall_grade = 'A';
else if (average >= 80)
	overall_grade = 'B';
else if (average >= 70)
	overall_grade = 'C';
else if (average >= 60)
	overall_grade = 'D';
else
	overall_grade = 'F';

																					//output section
outfile << setw(30) << "Course Grade Report" << endl;
outfile << setw(30) << "===================" << endl << endl;
outfile << setw(10) << "Professor: " << setw(5) << professor_name << endl;
outfile << setw(10) << "Semester: " << setw(5) << semester << endl;
outfile << setw(10) << "Course Name: " << setw(7) << course << endl;
outfile << setw(10) << "Credits: " << setw(7) << credit << endl << endl;
outfile << setw(10) << "Student" << setw(4) << "Midterm" << setw(4)
		  << "Final" << setw(4)<< "Project" << setw(4) << "Average"
		  << setw(4) << "Grade" << endl;
outfile << setw(10) << "=======" << setw(4) << "=======" << setw(4)
		  << "=====" << setw(4)
		  << "=======" << setw(4) << "=======" << setw(4)<< "=====" << endl;
outfile << setw(10) << student_name << setw(4) << midterm_grade << setw(4)
		  << final_grade << setw(4)<< project << setw(4) << average << setw(4)
		  << overall_grade << endl;


Anybody who can provide help, it would be greatly appreciated, because i need to finish this pretty soon. Thanks in advance.
  #2  
Old 17-Dec-2005, 23:31
Paramesh's Avatar
Paramesh Paramesh is offline
Regular Member
 
Join Date: Sep 2005
Location: The Milky Way
Posts: 927
Paramesh is a jewel in the roughParamesh is a jewel in the roughParamesh is a jewel in the rough

Re: In Need of Some Serious Help...compiling errors [C++]


Hi,

Welcome to GIDForums.
What compiler are you using?

First using ".h" is depreciated in c++.
remove the .h in all the includes.
conio.h is not a standard library. So remove it also.
And use <cmath> instead of math.h

So, the include section is something like this:
CPP / C++ / C Code:
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include <cmath>

Then , ignore the typedefs(only for a while) and write a simple program
The typedef is the cause of all the confusion.

The main function should be int main() rather than void main().

Regarding this:
CPP / C++ / C Code:
do { 
	cout << "Enter the Number of Students: ";
	cin >> num_students;
	}
while (num_students > 0 && num_students <= 30);
{	
//code...
Dont confuse do while statement.
To avoid this confusion, you could just write like this:
CPP / C++ / C Code:
do { 
	cout << "Enter the Number of Students: ";
	cin >> num_students;
	} while (num_students > 0 && num_students <= 30);
for (loc_value = 0; loc_value <= num_students; loc_value++)
// code...

All of the errors come from this area:
CPP / C++ / C Code:
//the following is to calculate the average
average = ((2 * midterm_grade) + (3 * final_grade) + project) / 6;
Because you should declare the average as a float rather than an array.
And you should use a loop to calculate the average, rather than a single statement.
Something like this:
CPP / C++ / C Code:
average = 0;
for(int i = 0; i < num_students; i++)
{
    average = ((2 * midterm_grade[i]) + (3 * final_grade[i]) + project[i]) / 6;
}

Best Regards,
Paramesh.
__________________

Don't walk in front of me, I may not follow.
Don't walk behind me, I may not lead.
Just walk beside me and be my friend.
  #3  
Old 18-Dec-2005, 02:07
needcishelp needcishelp is offline
New Member
 
Join Date: Dec 2005
Posts: 13
needcishelp is on a distinguished road

Re: In Need of Some Serious Help...compiling errors [C++]


this is how it looks now. Btw, im using turbo c++ for this. I am still really confused about all the typedef's...any ideas? Here's the code as of right now...Also, i don't get what you mean by the .h is depreciated. I've used it on all my other progs so far with no problems.

Also, the conio.h is a turboc++ library part.

Thanks for all your help!
CPP / C++ / C Code:
//***********************Preprocessor Directives****************************
#include <fstream.h>
#include <iomanip.h>
#include <iostream.h>
#include <string.h>
#include <conio.h>
#include <math.h>

using namespace std;
//************************** main ******************************************
void main()
{
	const int		MAX_SIZE = 30;
					NAME_SIZE = 31;

	typedef char STRING_30[NAME_SIZE];
	typedef STRING_30 LIST_S30[MAX_SIZE];
	typedef int LIST_I[MAX_SIZE];

	int				num_students,		//array size
					loc_value,			//lcv/array index
					choice,
					credit;				//credits recieved for the class
	char			drive[2],
					disk_file[15],
					file[9],
					course[20],			//course name
					semester[15],			
					professor_name[25];
       float			       average;			//average of midterm, final and project grades
	LIST_I			     midterm_grade,		
					final_grade,
					project;
	LIST_S30		   student_name,
				        overall_grade;
	ofstream		    outfile;


																					//input section
cout << "Enter Professor Name: ";
cin >> ws;
cin.getline (professor_name,(sizeof(professor_name)-1));
cout << "Semester: " ;
cin >> ws;
cin.getline (semester,(sizeof(semester) -1));
cout << "Course Name: ";
cin >> ws;
cin.getline (course,(sizeof(course)-1));
cout << "Number of Credits: ";
cin >> credit;

if (credit < 1 || credit > 6)
	cout << "Enter Number of Credits (1-6): ";

do { 
	cout << "Enter the Number of Students: ";
	cin >> num_students;
	} while (num_students > 0 && num_students <= 30);

{	for (loc_value = 0; loc_value <= num_students; loc_value++)
	cout << "Enter Student Name: ";
	cin >> ws;
	cin.getline(student_name[loc_value], (sizeof (student_name[loc_value])-1));
	cout << "Enter Midterm Grade: ";
	cin >> midterm_grade[loc_value];
	cout << "Enter Final Grade: ";
	cin >> final_grade[loc_value];
	cout << "Enter Project Grade: ";
	cin >> project[loc_value];
}

																					//process section

average = 0;
for(int i = 0; i < num_students; i++)
{
    average = ((2 * midterm_grade[i]) + (3 * final_grade[i]) + project[i]) / 6;
}


if (average >= 90)
	overall_grade = 'A';
else if (average >= 80)
	overall_grade = 'B';
else if (average >= 70)
	overall_grade = 'C';
else if (average >= 60)
	overall_grade = 'D';
else
	overall_grade = 'F';

																					//output section
outfile << setw(30) << "Course Grade Report" << endl;
outfile << setw(30) << "===================" << endl << endl;
outfile << setw(10) << "Professor: " << setw(5) << professor_name << endl;
outfile << setw(10) << "Semester: " << setw(5) << semester << endl;
outfile << setw(10) << "Course Name: " << setw(7) << course << endl;
outfile << setw(10) << "Credits: " << setw(7) << credit << endl << endl;
outfile << setw(10) << "Student" << setw(4) << "Midterm" << setw(4)
		  << "Final" << setw(4)<< "Project" << setw(4) << "Average"
		  << setw(4) << "Grade" << endl;
outfile << setw(10) << "=======" << setw(4) << "=======" << setw(4)
		  << "=====" << setw(4)
		  << "=======" << setw(4) << "=======" << setw(4)<< "=====" << endl;
outfile << setw(10) << student_name << setw(4) << midterm_grade << setw(4)
		  << final_grade << setw(4)<< project << setw(4) << average << setw(4)
		  << overall_grade << endl;
  #4  
Old 18-Dec-2005, 06:22
Paramesh's Avatar
Paramesh Paramesh is offline
Regular Member
 
Join Date: Sep 2005
Location: The Milky Way
Posts: 927
Paramesh is a jewel in the roughParamesh is a jewel in the roughParamesh is a jewel in the rough

Re: In Need of Some Serious Help...compiling errors [C++]


typedef introduce a new name for a type.
For example, consider this case:
CPP / C++ / C Code:
    typedef int integer;
    integer i;
Now, integer is nothing but int.

As in your case,
CPP / C++ / C Code:
    typedef char STRING_30[NAME_SIZE];
    typedef STRING_30 LIST_S30[MAX_SIZE];
    typedef int LIST_I[MAX_SIZE];
Is totally confusing.

First, you have created a typedef for string_30.
But string_30 is again typedef(ed) to list_s30.
Why this confusion?

So, it is better to leave the typedef for a while.
We'll switch over to typedef later.(After we complete the program)

Regarding the depreciated libraries:
Quote:
Originally Posted by davekw7x
Another aside: the word is deprecated, not depreciated. This is the language of the C++ standard. (You can look it up.) In this context it expresses disapproval, in the sense that these headers will not always be supported.

The ANSI C++ standard specifies the following modification:
  • Header file names no longer maintain the .h extension.This extension h simply disappears and files previously known as iostream.h become iostream (without .h).
  • Header files that come from the C language now have to be preceded by a c character in order to distinguish them from the new C++ exclusive header files that have the same name. For example stdio.h becomes cstdio .
  • All classes and functions defined in standard libraries are under the std namespace.
And regarding conio.h:
It is not a part of the standard.

I Know this is too much. If you are confused, just forget the 23 lines above.

Now to the program:
You need to make two changes:

Delete the typedef lines for a while
and Rewrite the whole program without the typedefs.
(There is a whole bunch of errors, which cant be explained in text)

Here is a start:
1. Whenever you use an array, you need a loop. Because grade[i] is different from grade.
2. I'm adding a little bit modification for the average variable.
Declare the average as a float array, and compute average for each student.

Regards,
Paramesh
__________________

Don't walk in front of me, I may not follow.
Don't walk behind me, I may not lead.
Just walk beside me and be my friend.
  #5  
Old 18-Dec-2005, 16:27
needcishelp needcishelp is offline
New Member
 
Join Date: Dec 2005
Posts: 13
needcishelp is on a distinguished road

Re: In Need of Some Serious Help...compiling errors [C++]


I ran the program and after fixing the things you mentioned, this is what it askedme for but it shouldnt have asked me for an extra student since i only entered 1...NEVERMIND, I FOUND THAT WE JUST NEEDED A < IN THE CODE, NOT A <=


" Course Grade Report
===================

Professor: John
Semester: Fall 2005
Course: Math
Credits: 4
StudentMidtermFinalProjectAverageGrade
======================================
0x22f9480x22fbc80x22fc480x22fcc8 93 5


Press any key to continue . . ."

Here is my program code and I did the best to fix the corrections that you pointed out.

CPP / C++ / C Code:
//************************ Preprocessor Directives *****************************
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

//********************************* Main ***************************************
int main()
{
const int       MAX_SIZE = 30,
                NAME_SIZE = 21,
                LET_GRADE;
                
typedef char STRING_20[NAME_SIZE];
typedef STRING_20 LIST_S20[MAX_SIZE];
typedef int LIST_I[MAX_SIZE];

int             choice,
                average,              //average before letter grade
                student_amt,          //array size
                credits,
                grade,
                loc_value;            //lcv/array index
char            drive[2],
                disk_file[15],
                file[9],
                prof_name[25],
                semester[15],
                course_name[25];
ofstream        outfile;
LIST_I          i,
                proj_grade,
                final_grade,
                mid_grade;
LIST_S20        stud_name,            //name of student in array row
                letter_grade;         //letter grade at end of arrays


                                            // input section
cout << "Enter Professor Name: ";
cin >> ws;
cin.getline (prof_name, (sizeof(prof_name)-1));
cout << "Enter Semester (season year): " ;
cin >> ws;
cin.getline (semester, (sizeof (semester) -1));
cout << "Enter Course Name: ";
cin >> ws;
cin.getline (course_name , (sizeof(course_name)-1));
cout << "Enter Credits for the Course: ";
cin >> credits;

if(credits < 1 || credits > 6)
    cout << endl <<"Incorrect entry! Please enter a credit amount of 1-6" 
         << endl << endl;
    
do { 
	cout << "Enter the Number of Students: ";
	cin >> student_amt;
	} while (student_amt < 0 || student_amt > 30);
for (loc_value = 0; loc_value <= student_amt; loc_value++)

{
    cout << "Enter the Student Name: ";
    cin >> ws;
    cin.getline (stud_name[loc_value],(sizeof(stud_name[loc_value])-1));
	cout << "Enter the Midterm Grade: ";
	cin >> mid_grade[loc_value];
	cout << "Enter the Final Grade: ";
	cin >> final_grade[loc_value];
	cout << "Enter the Project Grade: ";
	cin >> proj_grade[loc_value];
}

                                            //process section
average = 0;
for(int i = 0; i < student_amt; i++)
{
    average = ((2 * mid_grade[i]) + (3 * final_grade[i]) + proj_grade[i]) / 6;
}

if (average[i] >= 90)
	grade = 1;
else if (average[i] >= 80)
	grade = 2;
else if (average[i] >= 70)
	grade = 3;
else if (average[i] >= 60)
	grade = 4;
else
	grade = 5;	

	      
                                            // output section
system ("cls");
cout << "Output to console (1) or disk file (2): ";
cin >> choice;
if ( choice == 1 )
        {
	       system ("cls");
	       outfile.open("con");
        }    
else
        {
            cout << "Which drive: a, b, c, d, e, or f? ";
            cin >> drive;
            strcpy(disk_file, drive);
            strcat(disk_file, ":");
            cout << "Enter a results file name: ";
            cin >> file;
            strcat(disk_file, file);
            strcat(disk_file, ".dta");
            outfile.open(disk_file);
            }
outfile << setiosflags(ios::showpoint | ios::fixed) << setprecision(2);

outfile << setw(30) << "Course Grade Report" << endl;
outfile << setw(30) << "===================" << endl << endl;
outfile << setw(10) << "Professor: " << setw(5) << prof_name << endl;
outfile << setw(10) << "Semester: " << setw(5) << semester << endl;
outfile << setw(10) << "Course: " << setw(7) << course_name << endl;
outfile << setw(10) << "Credits: " << setw(7) << credits << endl;
outfile << setw(10) << "Student" << setw(4) << "Midterm" << setw(4) << "Final" 
        << setw(4) << "Project" << setw(4) << "Average" << setw(4) << "Grade" 
        << endl;
outfile << setw(10) << "=======" << setw(4) << "=======" << setw(4) << "=====" 
        << setw(4) << "=======" << setw(4) << "=======" << setw(4) << "=====" 
        << endl;
outfile << setw(10) << stud_name << setw(4) << mid_grade << setw(4) 
        << final_grade << setw(4) << proj_grade << setw(4) << average << setw(4)
        << grade << endl;

        if (loc_value % 3 ==0)
		      outfile << endl;

Also I did not change average to a float because the grades will al be whole numbers.

I dont know how to make this program work without trying to use the typedefs and they are wutsmaking the problem.

I think that I need a const int for the size of the letter grade but i am not sure how to make that a typedef.

thanks for all your help.
  #6  
Old 18-Dec-2005, 18:46
needcishelp needcishelp is offline
New Member
 
Join Date: Dec 2005
Posts: 13
needcishelp is on a distinguished road

Re: In Need of Some Serious Help...compiling errors [C++]


I messed with the outfile to try and make it display properly but now the numbers are not showing properly only the average and the letter grade work.

here is what it looks like:

CPP / C++ / C Code:
           Course Grade Report
           ===================

Professor:  John
Semester: Fall 2005
  Course:    Math
 Credits:       3
   Student  Midterm    Final  Project  Average    Grade
   =======  =======    =====  =======  =======    =====

  2292960        02089879352       91        A


Press any key to continue . . .


It should display more then one student but doesn't.

Also I understand the general idea of the two dimensional array, I just don't quite understand which section I am suposed to make the change(s).
  #7  
Old 18-Dec-2005, 18:53
Paramesh's Avatar
Paramesh Paramesh is offline
Regular Member
 
Join Date: Sep 2005
Location: The Milky Way
Posts: 927
Paramesh is a jewel in the roughParamesh is a jewel in the roughParamesh is a jewel in the rough

Re: In Need of Some Serious Help...compiling errors [C++]


Quote:
Originally Posted by needcishelp
It should display more then one student but doesn't.
Because you are not using loops, to print out the value.
Put this part under a loop:
CPP / C++ / C Code:
for(int i = 0; i < num_students; i++) {
            cout << setw(10) << student_name[i] << setw(4) << midterm_grade[i] << setw(4)
                 << final_grade[i] << setw(4)<< project << setw(4) << average << setw(4)
                 << overall_grade[i] << endl;
    }


Note that when you use two dimensional strings, you need a loop to print them out.

The program still has errors, and you are online now, we'll correct them one by one. OK?

Regards,
Paramesh.
__________________

Don't walk in front of me, I may not follow.
Don't walk behind me, I may not lead.
Just walk beside me and be my friend.
  #8  
Old 18-Dec-2005, 19:02
needcishelp needcishelp is offline
New Member
 
Join Date: Dec 2005
Posts: 13
needcishelp is on a distinguished road

Re: In Need of Some Serious Help...compiling errors [C++]


I'm confused. Is this what you mean?
CPP / C++ / C Code:
//************************ Preprocessor Directives *****************************
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include <cmath>

using namespace std;
//********************************* Main ***************************************
int main()
{
const int       MAX_SIZE = 30,
                NAME_SIZE = 21,
                LET_GRADE = 2;
                
typedef char STRING_20[NAME_SIZE];
typedef STRING_20 LIST_S20[MAX_SIZE];
typedef char STRING_2[LET_GRADE];
typedef STRING_2 LIST_S2[MAX_SIZE];
typedef int LIST_I[MAX_SIZE];

int             choice,
                average,              //average before letter grade
                student_amt,          //array size
                credits,
                loc_value;            //lcv/array index
char            drive[2],
                disk_file[15],
                file[9],
                grade,
                prof_name[25],
                semester[15],
                course_name[25];
ofstream        outfile;
LIST_I          i,
                proj_grade,
                final_grade,
                mid_grade;
LIST_S20        stud_name;            //name of student in array row
LIST_S2         letter_grade;         //letter grade at end of arrays


                                            // input section
cout << "Enter Professor Name: ";
cin >> ws;
cin.getline (prof_name, (sizeof(prof_name)-1));
cout << "Enter Semester (season year): " ;
cin >> ws;
cin.getline (semester, (sizeof (semester) -1));
cout << "Enter Course Name: ";
cin >> ws;
cin.getline (course_name , (sizeof(course_name)-1));
cout << "Enter Credits for the Course: ";
cin >> credits;

if(credits < 1 || credits > 6)
    cout << endl <<"Incorrect entry! Please enter a credit amount of 1-6" 
         << endl << endl;
    
do { 
	cout << "Enter the Number of Students: ";
	cin >> student_amt;
	} while (student_amt < 0 || student_amt > 30);
for (loc_value = 0; loc_value < student_amt; loc_value++)

{
    cout << "Enter the Student Name: ";
    cin >> ws;
    cin.getline (stud_name[loc_value],(sizeof(stud_name[loc_value])-1));
	cout << "Enter the Midterm Grade: ";
	cin >> mid_grade[loc_value];
	cout << "Enter the Final Grade: ";
	cin >> final_grade[loc_value];
	cout << "Enter the Project Grade: ";
	cin >> proj_grade[loc_value];

for(int i = 0; i < num_students; i++) {
            cout << setw(10) << student_name[i] << setw(4) << midterm_grade[i] << setw(4)
                 << final_grade[i] << setw(4)<< project << setw(4) << average << setw(4)
                 << overall_grade[i] << endl;
    }
}

                                            //process section
average = 0;
for(int i = 0; i < student_amt; i++)
{
    average = ((2 * mid_grade[i]) + (3 * final_grade[i]) + proj_grade[i]) / 6;
}

{
if (average[i] >= 90)
	grade = 'A';
else if (average[i] >= 80)
	grade = 'B';
else if (average[i] >= 70)
	grade = 'C';
else if (average[i] >= 60)
	grade = 'D';
else if (average[i]<=59)
	grade = 'F';	
}
	      
                                            // output section
system ("cls");
cout << "Output to console (1) or disk file (2): ";
cin >> choice;
if ( choice == 1 )
        {
	       system ("cls");
	       outfile.open("con");
        }    
else
        {
            cout << "Which drive: a, b, c, d, e, or f? ";
            cin >> drive;
            strcpy(disk_file, drive);
            strcat(disk_file, ":");
            cout << "Enter a results file name: ";
            cin >> file;
            strcat(disk_file, file);
            strcat(disk_file, ".dta");
            outfile.open(disk_file);
            }
outfile << setiosflags(ios::showpoint | ios::fixed) << setprecision(2);

outfile << setw(30) << "Course Grade Report" << endl;
outfile << setw(30) << "===================" << endl << endl;
outfile << setw(10) << "Professor: " << setw(5) << prof_name << endl;
outfile << setw(10) << "Semester: " << setw(5) << semester << endl;
outfile << setw(10) << "Course: " << setw(7) << course_name << endl;
outfile << setw(10) << "Credits: " << setw(7) << credits << endl;
outfile << setw(10) << "Student" << setw(9) << "Midterm" << setw(9) << "Final" 
        << setw(9) << "Project" << setw(9) << "Average" << setw(9) << "Grade" 
        << endl;
outfile << setw(10) << "=======" << setw(9) << "=======" << setw(9) << "=====" 
        << setw(9) << "=======" << setw(9) << "=======" << setw(9) << "=====" 
        << endl;
outfile << setw(10) << stud_name[loc_value] << setw(9) << mid_grade[loc_value]
        << setw(9) << final_grade[loc_value] << setw(9) 
        << proj_grade[loc_value] << setw(9) << average << setw(9)
        << grade << endl;
  #9  
Old 18-Dec-2005, 19:05
Paramesh's Avatar
Paramesh Paramesh is offline
Regular Member
 
Join Date: Sep 2005
Location: The Milky Way
Posts: 927
Paramesh is a jewel in the roughParamesh is a jewel in the roughParamesh is a jewel in the rough

Re: In Need of Some Serious Help...compiling errors [C++]


No! Since you have changed some parts of the program.

Ok. here is the modification you have to do now:
Change this first, and check whether you got it right:
CPP / C++ / C Code:
for (loc_value = 0; loc_value < student_amt; loc_value++)
{
    outfile << setw(10) << stud_name[loc_value] << setw(9) << mid_grade[loc_value]
        << setw(9) << final_grade[loc_value] << setw(9) 
        << proj_grade[loc_value] << setw(9) << average << setw(9)
        << grade << endl;
}
The last part of the program.


Paramesh.
__________________

Don't walk in front of me, I may not follow.
Don't walk behind me, I may not lead.
Just walk beside me and be my friend.
  #10  
Old 18-Dec-2005, 19:13
needcishelp needcishelp is offline
New Member
 
Join Date: Dec 2005
Posts: 13
needcishelp is on a distinguished road

Re: In Need of Some Serious Help...compiling errors [C++]


So this is what I have now:

CPP / C++ / C Code:
//************************ Preprocessor Directives *****************************
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include <cmath>

using namespace std;
//********************************* Main ***************************************
int main()
{
const int       MAX_SIZE = 30,
                NAME_SIZE = 21,
                LET_GRADE = 2;
                
typedef char STRING_20[NAME_SIZE];
typedef STRING_20 LIST_S20[MAX_SIZE];
typedef char STRING_2[LET_GRADE];
typedef STRING_2 LIST_S2[MAX_SIZE];
typedef int LIST_I[MAX_SIZE];

int             choice,
                average,              //average before letter grade
                student_amt,          //array size
                credits,
                loc_value;            //lcv/array index
char            drive[2],
                disk_file[15],
                file[9],
                grade,
                prof_name[25],
                semester[15],
                course_name[25];
ofstream        outfile;
LIST_I          i,
                proj_grade,
                final_grade,
                mid_grade;
LIST_S20        stud_name;            //name of student in array row
LIST_S2         letter_grade;         //letter grade at end of arrays


                                            // input section
cout << "Enter Professor Name: ";
cin >> ws;
cin.getline (prof_name, (sizeof(prof_name)-1));
cout << "Enter Semester (season year): " ;
cin >> ws;
cin.getline (semester, (sizeof (semester) -1));
cout << "Enter Course Name: ";
cin >> ws;
cin.getline (course_name , (sizeof(course_name)-1));
cout << "Number of Credits for the Course: ";
cin >> credits;

if(credits < 1 || credits > 6)
    cout << endl <<"Bad Entry! Please enter a credit amount between 1-6" 
         << endl << endl;
    
do { 
	cout << "Enter Number of Students: ";
	cin >> student_amt;
	} while (student_amt < 0 || student_amt > 30);
for (loc_value = 0; loc_value < student_amt; loc_value++)

{
    cout << "Enter Student Name: ";
    cin >> ws;
    cin.getline (stud_name[loc_value],(sizeof(stud_name[loc_value])-1));
	cout << "Enter Midterm Grade: ";
	cin >> mid_grade[loc_value];
	cout << "Enter Final Grade: ";
	cin >> final_grade[loc_value];
	cout << "Enter the Project Grade: ";
	cin >> proj_grade[loc_value];
	
	for (loc_value = 0; loc_value < student_amt; loc_value++)
}

                                            //process section
average = 0;
for(int i = 0; i < student_amt; i++)
{
    average = ((2 * mid_grade[i]) + (3 * final_grade[i]) + proj_grade[i]) / 6;
}

{
if (average[i] >= 90)
	grade = 'A';
else if (average[i] >= 80)
	grade = 'B';
else if (average[i] >= 70)
	grade = 'C';
else if (average[i] >= 60)
	grade = 'D';
else if (average[i]<=59)
	grade = 'F';	
}
	      
                                            // output section
system ("cls");
cout << "Output to console (1) or disk file (2): ";
cin >> choice;
if ( choice == 1 )
        {
	       system ("cls");
	       outfile.open("con");
        }    
else
        {
            cout << "Which drive: a, b, c, d, e, or f? ";
            cin >> drive;
            strcpy(disk_file, drive);
            strcat(disk_file, ":");
            cout << "Enter a results file name: ";
            cin >> file;
            strcat(disk_file, file);
            strcat(disk_file, ".dta");
            outfile.open(disk_file);
            }
outfile << setiosflags(ios::showpoint | ios::fixed) << setprecision(2);

outfile << setw(30) << "Course Grade Report" << endl;
outfile << setw(30) << "===================" << endl << endl;
outfile << setw(10) << "Professor: " << setw(5) << prof_name << endl;
outfile << setw(10) << "Semester: " << setw(5) << semester << endl;
outfile << setw(10) << "Course: " << setw(7) << course_name << endl;
outfile << setw(10) << "Credits: " << setw(7) << credits << endl;
outfile << setw(10) << "Student" << setw(9) << "Midterm" << setw(9) << "Final" 
        << setw(9) << "Project" << setw(9) << "Average" << setw(9) << "Grade" 
        << endl;
outfile << setw(10) << "=======" << setw(9) << "=======" << setw(9) << "=====" 
        << setw(9) << "=======" << setw(9) << "=======" << setw(9) << "=====" 
        << endl;
for (loc_value = 0; loc_value < student_amt; loc_value++)
{
    outfile << setw(10) << stud_name[loc_value] << setw(9) << mid_grade[loc_value]
        << setw(9) << final_grade[loc_value] << setw(9) 
        << proj_grade[loc_value] << setw(9) << average << setw(9)
        << grade << endl;
}

My problem is that now, the average and grade in the outfile are not being correctly computed. This is what it looks like.
CPP / C++ / C Code:
"           Course Grade Report
           ===================

Professor:  John
Semester: Fall 2005
  Course:    Math
 Credits:       3
   Student  Midterm    Final  Project  Average    Grade
   =======  =======    =====  =======  =======    =====
      Mike       90       95      100       56        F
       Dan       99       40       20       56        F


Press any key to continue . . .
"
 
 

Recent GIDBlogMeeting the populace 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
Winsock error when compiling FLTK 2.0 Projects mauriciorossi FLTK Forum 3 16-Aug-2005 10:18
C++ Compiling Error pointer MS Visual C++ / MFC Forum 3 12-May-2005 04:08
Compiling Errors ToddSAFM C++ Forum 22 18-Dec-2004 11:42
help to debug complier errors nkhambal C Programming Language 3 04-Oct-2004 08:26
Can somebody look at this and point out any errors to me soulfly C Programming Language 7 31-Mar-2004 09:45

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

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


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