|
Need help in this source code C++
|
|
the main problem is that when i type in my whole name it goes berserk... Enter employee's name:michael jan yamasaki Enter employee's monthly salary: The bonus you will be receiving this month is :-4.62798e+061 Your total salary this month is :-1.38839e+062 Press any key to continue but when i type in short names it works... Enter employee's name:michael Enter employee's monthly salary:7000 The bonus you will be receiving this month is :7000 Your total salary this month is :14000 Press any key to continue can anyone help me? Our professor wont even teach us -_-... she just fly away whenever she enters the room, so we just studied the book by ourselves(and yeah i suck... we use visual studio 2003)... heres the code... i didnt put the if else statement because it gives b tag is not closed at position 1103! #include <iostream.h>
int main()
{
double b,ts,s;
char n[20];
cout<<"Enter employee's name:";
cin>>n;
cout<<"nEnter employee's monthly salary:";
cin>>s;
if (s > 6999)
return 0;
} |
|
Re: Need help in this source code C++
Link |
by
|
|
You should use cin.getline() instead of >> to load the employee's name into the variable n. See: http://www.cplusplus.com/reference/iostream/istream/getline.html
|
|
Re: Need help in this source code C++
Link |
by
|
|
char (variable)[20] -> that variable can store up to 20 characters char (variable)[256] -> that variable can store up to 256 characters |
|
Re: Need help in this source code C++
|
| Of course he could just use the string class and be done with character arrays altogether. He can also set the noskipws flag to be able to use the << operator to grab such input. |