Originally Posted by
Salem
> It doesn't even ask me to enter the details for the second student. Where did I go wrong?
You're inputting "25th April 2011" into a single string, using >>
Which means, with space as a separator, you get "25th" stored in DofAdm, and then you try to parse "April" as an integer for marks.
This naturally fails, putting the whole cin stream into an error state, and thus all remaining input is skipped.
Thanks a lot, Salem. I understand it now. Perhaps, I should try to use "_" while inputting the date of admission. What do you say? Please let me know. Or, perhaps I could use a structure DATE to declare the date of admission.
Originally Posted by
Salem
> I don't even know how get columns of "*" and how to increase the size of "STUDENTS' DATA" and how place it in the center at the top
This is a lot harder than it might first seem (and changing font size/face in a console is pretty much impossible to begin with).
Assuming you're using win32 consoles, read this tutorial.
Win32 Console Applications 1
Once you know how to position the cursor at any point on the screen, you should be able to draw your box.
I think I should stop worrying too much to make it nice looking rather should focus on learning programming techniques. Suppose, I don't want to change the size or face of the "STUDENTS' DATA", then is this 'easily' possible to get the surrounding vertical columns of "*"?
Thanks a lot for all the help.
EDIT:
I was 'manually' able to get the vertical column of "*" on left side of output. Is there some way to get it 'automatically'? How do I get the column on right of side of the output?
Code:
// displaying students' data using a user-define functionS
#include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace std;
/////////////////////////////////////////////////////////////////
struct STUDENT
{ string name, DofAdm, sex; int age, marks; };
/////////////////////////////////////////////////////////////////
void prntborder(char, int);
void prntstudent (STUDENT);
int main ()
{
STUDENT s;
char ch;
do
{
int j=1;
cout << "enter the details" << endl;
cout << endl;
cout << "enter details of " << "#" << j << " student" << endl;
cout << "enter name: "; cin >> s.name;
cout << "enter sex: "; cin >> s.sex;
cout << "enter age: "; cin >> s.age;
cout << "enter date of admission: "; cin >> s.DofAdm;
cout << "enter marks: "; cin >> s.marks;
cout << endl;
cout << "STUDENT DATA" << endl;
prntborder('*', 25);
prntstudent(s);
prntborder('*', 25);
cout << endl;
cout << "Do you want to enter new data? "; cin >> ch;
j = j++;
cout << endl;
}
while (ch != 'n');
system("pause");
return 0;
}
//--------------------------------------------------------
// definition for a function which prints student structure
// prntstudent (STUDENT)
void prntstudent (STUDENT dummy)
{
cout << "* Name is: " << dummy.name << endl;
cout << "* Sex is: " << dummy.sex << endl;
cout << "* Age is: " << dummy.age << endl;
cout << "* Date of Admission is: " << dummy.DofAdm << endl;
cout << "* Mark: " << dummy.marks << endl;
}
//--------------------------------------------------------
//--------------------------------------------------------
// definition for a function to make the data output pretty
// prntborder()
// function definition
void prntborder(char ch, int n)
{
for (int j=0; j<=n; j++)
{
cout << ch;
}
cout << endl;
}
//--------------------------------------------------------
Output:
Code:
enter the details
enter details of #1 student
enter name: jack
enter sex: male
enter age: 16
enter date of admission: 1stDec2011
enter marks: 70
STUDENT DATA
**************************
* Name is: jack
* Sex is: male
* Age is: 16
* Date of Admission is: 1stDec2011
* Mark: 70
**************************
Do you want to enter new data?