can anyone find the error in my programming?

// ------------------------------------------------------------------
// File name: grades.cpp
//
// Assign ID: PROG4
//
// Due Date: 2/21/12 at 11pm
//
// Purpose: Write a program to rearrange and format three lines of
// student data; data items are separated by whitespace.
//
//
// Author: bfields Byron Fields
//
// ------------------------------------------------------------------

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

int main ()
{
//-| ----------------------------------------------------------------
//-| Declare Variables
//-| ----------------------------------------------------------------

long Student_ID; //-| Student's ID #
string FirstName; //-| Student's First Name
string LastName; //-| Student's Last Name
int CourseLoad; //-| Course Load
int CumHours; //-| Cumalative Hours
float GPA; //-| Student's GPA



//-| ----------------------------------------------------------------
//-| 1. Read data for the first student.
//-| ----------------------------------------------------------------
getline(cin, Student_ID+FirstName+Lastname+CourseLoad+CumHours+GPA);
//-| ----------------------------------------------------------------
//-| 2. Read data for the second student.
//-| ----------------------------------------------------------------
getline(cin, Student_ID+FirstName+Lastname+CourseLoad+CumHours+GPA)
//-| ----------------------------------------------------------------
//-| 3. Read data for the third student.
//-| ----------------------------------------------------------------
getline(cin, Student_ID+FirstName+Lastname+CourseLoad+CumHours+GPA)
//-| ---------------------------------------------------------------------
//-| 4. Write report headings.
//-| ---------------------------------------------------------------------
cout << "====" << " " << "=========" << " " << "====" << " " << "=====" << " " << "==============" << endl;
cout << " " << endl;
cout << " GPA" << " " << "StudentID" << " " << "Load" << " " << "Hours" << " " << "Student_Name " << endl;
cout << " " << endl;
cout << "====" << " " << "=========" << " " << "====" << " " << "=====" << " " << "==============" << endl;
cout << " " << endl;
//-| ---------------------------------------------------------------------
//-| 5. Write data for the first student.
//-| ---------------------------------------------------------------------
cout << right << setw(4) << fixed << setprecision(2) << GPA << right << setw(9) << Student_ID << right << setw(4) << CourseLoad << right << setw(5) << CumHours << left << FirstName << ", " << LastName << endl;
//-| ---------------------------------------------------------------------
//-| 6. Write data for the second student.
//-| ---------------------------------------------------------------------
cout << right << setw(4) << fixed << setprecision(2) << GPA << right << setw(9) << Student_ID << right << setw(4) << CourseLoad << right << setw(5) << CumHours << left << FirstName << ", " << LastName << endl;
//-| ---------------------------------------------------------------------
//-| 7. Write data for the third student
//-| ---------------------------------------------------------------------
cout << right << setw(4) << fixed << setprecision(2) << GPA << right << setw(9) << Student_ID << right << setw(4) << CourseLoad << right << setw(5) << CumHours << left << FirstName << ", " << LastName << endl;
cout << " " << endl;
//-| ----------------------------------------------------------------------
//-| 8. Write report footer.
//-| ----------------------------------------------------------------------
cout << "====" << " " << "=========" << " " << "====" << " " << "=====" << " " << "==============" << endl;


return 0;
}
you are trying to add int with string..

Student_ID+FirstName+Lastname+CourseLoad+CumHours+GPA

int can only add with int. + your getline makes no sense
Last edited on
the outline he gave us said to read all the data at once. how else would i accomplish this?
Assignment ID: PROG4

File name(s): (1) grades.cpp

Due: (1) Sunday, Feb 19 at 4 pm


Description: (1) Write a program to rearrange and format three lines of
student data; data items are separated by whitespace.
[grades.cpp]


Inputs: One input line contains all the data for one student:

ID Firstname Lastname Courseload CumHours GPA
byron, you can actually manipulate strings just like an array. Barring that, use a stringstream to separate portions based on some kind of marker, like a space.
thanks man, i made the assignment harder than it had to be... rewrote it like this:

cin >> Student_ID >> FirstName >> LastName >> CourseLoad >> CumHours;
my output came out like this though:

==== ========= ==== ===== ==============

GPA StudentID Load Hours Student_Name

==== ========= ==== ===== ==============

0.00 3 18 112.5, 411384112
0.00 3 18 112.5, 411384112
0.00 3 18 112.5, 411384112

==== ========= ==== ===== ==============

when it should be like this:

==== ========= ==== ===== ==============
GPA StudentID Load Hours Student_Name
==== ========= ==== ===== ==============
3.50 143841138 18 112 Jones, Edward
1.99 411384112 12 67 Frugal, Miser
3.83 118113428 6 31 Sapp, Marilyn
==== ========= ==== ===== ==============

any ideas?
Looks like bad variable assignment. Post your current code with [ code ] [ /code ] brackets.
you forgot to cin>>GPA
That's obviously not everything that's wrong with it, timmyyyyy. Look at how all three lines are identical to each other, and the names don't show up. Also, someone apparently has 112 1/2 credit hours, which shouldn't be possible.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
 #include <iostream>
#include <iomanip>
using namespace std;

int main ()
{
   //-| ----------------------------------------------------------------
   //-| Declare Variables
   //-| ----------------------------------------------------------------

   long Student_ID;    //-| Student's ID #
   string FirstName;   //-| Student's First Name
   string LastName;    //-| Student's Last Name
   int CourseLoad;     //-| Course Load
   int CumHours;       //-| Cumalative Hours
   float GPA;          //-| Student's GPA
   


   //-| ----------------------------------------------------------------
   //-| 1. Read data for the first student.
   //-| ----------------------------------------------------------------
   cin >> Student_ID >> FirstName >> LastName >> CourseLoad >> CumHours >> GPA;
   //-| ----------------------------------------------------------------
   //-| 2. Read data for the second student.
   //-| ----------------------------------------------------------------
   cin >> Student_ID >> FirstName >> LastName >> CourseLoad >> CumHours >> GPA;
   //-| ----------------------------------------------------------------
   //-| 3. Read data for the third student.
   //-| ----------------------------------------------------------------
   cin >> Student_ID >> FirstName >> LastName >> CourseLoad >> CumHours >> GPA;
   //-| ---------------------------------------------------------------------
   //-| 4. Write report headings.
   //-| ---------------------------------------------------------------------
   cout << "====" << "  " << "=========" << "  " << "====" << "  " << "=====" << "   " << "==============" << endl;
   cout << "                                               " << endl;
   cout << " GPA" << "  " << "StudentID" << "  " << "Load" << "  " << "Hours" << "   " << "Student_Name  " << endl;
   cout << "                                               " << endl;
   cout << "====" << "  " << "=========" << "  " << "====" << "  " << "=====" << "   " << "==============" << endl;
   cout << "                                               " << endl;
   //-| ---------------------------------------------------------------------
   //-| 5. Write data for the first student.
   //-| ---------------------------------------------------------------------
   cout << right << setw(4) << fixed << setprecision(2) << GPA << right << setw(9) << Student_ID << right << setw(4) << CourseLoad << right << setw(5) << CumHours << left << FirstName << ", " << LastName << endl;
   //-| ---------------------------------------------------------------------
   //-| 6. Write data for the second student.
   //-| ---------------------------------------------------------------------
   cout << right << setw(4) << fixed << setprecision(2) << GPA << right << setw(9) << Student_ID << right << setw(4) << CourseLoad << right << setw(5) << CumHours << left << FirstName << ", " << LastName << endl;
   //-| ---------------------------------------------------------------------
   //-| 7. Write data for the third student
   //-| ---------------------------------------------------------------------
   cout << right << setw(4) << fixed << setprecision(2) << GPA << right << setw(9) << Student_ID << right << setw(4) << CourseLoad << right << setw(5) << CumHours << left << FirstName << ", " << LastName << endl;
   cout << "                                               " << endl;
   //-| ----------------------------------------------------------------------
   //-| 8. Write report footer.
   //-| ----------------------------------------------------------------------
   cout << "====" << "  " << "=========" << "  " << "====" << "  " << "=====" << "   " << "==============" << endl;
   
   
   return 0;
}
Okay, byron. First thing you're doing is that you're copying over the top of your other values before you use those values. That's why you only have one output repeated three times. You need to either define an array to hold the information, or you need to use some sort of iteration to print them out as you receive them. In the case of your specific example, I'm thinking the array.

Second thing is that you're messing with the width on part of your output, but not all. This will cause (purely aesthetic) difficulties with formatting.

Third, a lot of the iomanip functions that you're using are going to screw up your other output. I would advise that if you have to use some sort of iomanip for something, that you should iomanip only exactly the same things on the same lines. This will help clear up what you're doing in your head, and make it easier to read. For example, if you need a precision of 2 on only the GPA, then make that it's own line (of code) and just don't move to the next line (of output) before you start putting out everything else.
Yep; the values get deleted.. the easiest solution would be :

(first print the table, then cin, cout; cin cout; cin cout)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  //-| ---------------------------------------------------------------------
   cout << "====" << "  " << "=========" << "  " << "====" << "  " << "=====" << "   " << "==============" << endl;
   cout << "                                               " << endl;
   cout << " GPA" << "  " << "StudentID" << "  " << "Load" << "  " << "Hours" << "   " << "Student_Name  " << endl;
   cout << "                                               " << endl;
   cout << "====" << "  " << "=========" << "  " << "====" << "  " << "=====" << "   " << "==============" << endl;
   cout << "                                               " << endl;

   //-| ----------------------------------------------------------------
   //-| 1. Read data for the first student.
   //-| ----------------------------------------------------------------
   cin >> Student_ID >> FirstName >> LastName >> CourseLoad >> CumHours >> GPA;

  //-| ---------------------------------------------------------------------
   //-| 5. Write data for the first student.
   //-| ---------------------------------------------------------------------
   cout << right << setw(4) << fixed << setprecision(2) << GPA << right << setw(9) << Student_ID << right << setw(4) << CourseLoad << right << setw(5) << CumHours << left << FirstName << ", " << LastName << endl;
   //-| --------------------------------------------------------------------- 

//do this for the 2nd and 3rd student as well 



also, there might be other errors of iomanip, you might want to verify what ciphermagi said
got the problem with the data handled
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
 // ------------------------------------------------------------------
// File name:   grades.cpp
//
// Assign ID:   PROG4
//
// Due Date:    2/21/12 at 11pm 
//
// Purpose:     Write a program to rearrange and format three lines of
//               student data; data items are separated by whitespace.
//               
//
// Author:      bfields Byron Fields
//
// ------------------------------------------------------------------

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

int main ()
{
   //-| ----------------------------------------------------------------
   //-| Declare Variables
   //-| ----------------------------------------------------------------

   long Student_ID;    //-| Student's ID #
   string FirstName;   //-| Student's First Name
   string LastName;    //-| Student's Last Name
   int CourseLoad;     //-| Course Load
   int CumHours;       //-| Cumalative Hours
   float GPA;          //-| Student's GPA
   long Student_ID2;    //-| Student #2's ID #
   string FirstName2;   //-| Student #2's First Name
   string LastName2;    //-| Student #2's Last Name
   int CourseLoad2;     //-| Course Load of student #2
   int CumHours2;       //-| Cumalative Hours of student #2
   float GPA2;          //-| Student #2's GPA
   long Student_ID3;    //-| Student #3's ID #
   string FirstName3;   //-| Student #3's First Name
   string LastName3;    //-| Student #3's Last Name
   int CourseLoad3;     //-| Course Load of student #3
   int CumHours3;       //-| Cumalative Hours of student #3
   float GPA3;          //-| Student #3's GPA
   


   //-| ----------------------------------------------------------------
   //-| 1. Read data for the first student.
   //-| ----------------------------------------------------------------
   cin >> Student_ID >> FirstName >> LastName >> CourseLoad >> CumHours >> GPA;
   //-| ----------------------------------------------------------------
   //-| 2. Read data for the second student.
   //-| ----------------------------------------------------------------
   cin >> Student_ID2 >> FirstName2 >> LastName2 >> CourseLoad2 >> CumHours2 >> GPA2;
   //-| ----------------------------------------------------------------
   //-| 3. Read data for the third student.
   //-| ----------------------------------------------------------------
   cin >> Student_ID3 >> FirstName3 >> LastName3 >> CourseLoad3 >> CumHours3 >> GPA3;
   //-| ---------------------------------------------------------------------
   //-| 4. Write report headings.
   //-| ---------------------------------------------------------------------
   cout << "====" << "  " << "=========" << "  " << "====" << "  " << "=====" << "   " << "==============" << endl;
   cout << " GPA" << "  " << "StudentID" << "  " << "Load" << "  " << "Hours" << "   " << "Student_Name  " << endl;
   cout << "====" << "  " << "=========" << "  " << "====" << "  " << "=====" << "   " << "==============" << endl;
   //-| ---------------------------------------------------------------------
   //-| 5. Write data for the first student.
   //-| ---------------------------------------------------------------------
   cout << right << setw(4) << fixed << setprecision(2) << GPA << right << setw(9) << Student_ID << right << setw(4) << CourseLoad << right << setw(5) << CumHours << left << FirstName << ", " << LastName << endl;
   //-| ---------------------------------------------------------------------
   //-| 6. Write data for the second student.
   //-| ---------------------------------------------------------------------
   cout << right << setw(4) << fixed << setprecision(2) << GPA2 << right << setw(9) << Student_ID2 << right << setw(4) << CourseLoad2 << right << setw(5) << CumHours2 << left << FirstName2 << ", " << LastName2 << endl;
   //-| ---------------------------------------------------------------------
   //-| 7. Write data for the third student
   //-| ---------------------------------------------------------------------
   cout << right << setw(4) << fixed << setprecision(2) << GPA3 << right << setw(9) << Student_ID3 << right << setw(4) << CourseLoad3 << right << setw(5) << CumHours3 << left << FirstName3 << ", " << LastName3 << endl;
   cout << "                                               " << endl;
   //-| ----------------------------------------------------------------------
   //-| 8. Write report footer.
   //-| ----------------------------------------------------------------------
   cout << "====" << "  " << "=========" << "  " << "====" << "  " << "=====" << "   " << "==============" << endl;
   
   
   return 0;
} 


but cant quite get the layout right
Topic archived. No new replies allowed.