-
string
i have a string and its in red and it dosne get an input i just king of skips over it... : (
Code:
#include <iostream>
#include <cstring>
using namespace std;
int x;
class database
{
private:
int id_number,rank;
float salery;
char string[20];
public:
void name ();
int position ();
void quarry ();
void respond ();
};
database data;
void database::name ()
{
cout<<"what is the nameof your employee?"<<endl;
cin.getline ( data.string, 20, '\n' );
}
int database::position ()
{
switch (rank)
{
case 1:
cout<<"cashier";
break;
case 2:
cout<<"Bag boy";
break;
case 3:
cout<<"delly";
break;
case 4:
cout<<"janeter";
break;
case 5:
cout<<"banker";
break;
case 6:
cout<<"produce";
break;
case 7:
cout<<"vice-maneger";
break;
case 8:
cout<<"maneger";
break;
case 10:
cout<<"1) cashier \n2) bag boy \n3) delly \n4) janeter \n5) banker \n";
cout<<"6) produce \n7) vice-maneger \n8) maneger \n";
cin>> rank;
position ();
cin.get();
break;
default:
cout<<"not in database";
break;
}
}
void database::quarry ()
{
cout<<"Employee id number?"<<endl;
cin>> id_number;
cout<<"The salery of employee :"<< id_number<<endl;
cin>> salery;
cout<<"The current status of employee? 10 for listings"<<endl;
cin>> rank;
}
void database::respond ()
{
cout<<"employee id number to employee ["<<string<<"] is :"<<id_number<<endl;
cout<<"employee salery :"<<salery<<" per hour"<<endl;
cout<<"your employee's position is :";
position ();
cout<<endl;
}
int main()
{
cout<<"how many employees do u have to enter?"<<endl;
cin>> x;
while (x > 0)
{
data.name ();
data.quarry ();
data.position ();
data.respond ();
cin.get();
x --;
}
}
-
This is a common problem that has to do with mixing >> and getline in the same program. Basically you'll need to call the ignore() method of cin to clear the input stream before you call the getline() method. The exact syntax you use with ignore() is up to you. Often the default ignore() will work, but if you want to be more robust, there are lot's more sophisticated options available.
-
btw, probably doesnt matter but....
maneger -> manager
vice-maneger -> vice-manager
janeter -> janitor
salery -> salary
u -> you
nameof -> name of
delly -> deli
And you should probably make yourself a default constructor so you can assign private variables.
-
i was really using it to get used to using a class but thanx
-
lol ya I know but I am so lonely and have nothing better to do... :(