// i wanna know why case 1 is not working ?
//and how i can make it working
//hope find an answer fast
// how i can make (cin) fun work well ?
#include<iostream>
#include<string>
#include<sstream>
#include<cstring>
using namespace std;
struct data{
string name;
long int id;
long int balance;
};
int main()
{
string c,b,y,u;
bool z;
long int d,dep;
int x,i,n,f,j=1,p=1,v;
string temp;
data w[50];
w[1].name="e1 f1";
w[1].id=29;
w[1].balance=3000;
w[2].name="e2 f2";
w[2].id=30;
w[2].balance=3000;
w[3].name="e3 f3";
w[3].id=31;
w[3].balance=2500;
w[4].name="e4 f4";
w[4].id=294042100;
w[4].balance=101;
w[5].name="e5 f5";
w[5].id=294061400;
w[5].balance=500;
for( ; ; )
{
cout<<" Please Choose Number of Operation u want to Do....."<<"\n"<<endl;
cout<<"1. Entering Record"<<endl;
cout<<"2. Searching the Record"<<endl;
cout<<"3. Deleting the Record"<<endl;
cout<<"4. Modification of Records"<<endl;
cout<<"5. Banking operation"<<endl;
cout<<"6. Data entry validation"<<endl;
cout<<"7. Print Clients List"<<endl;
cout<<endl;
cout<<"Number of operation is ";
cin>>x;
//getline(cin,temp);
//stringstream(temp)>>x;
//cin.get();
switch(x)
{
case 1 :
cout<<"\n Entering Record"<<endl;
cout<<"\n"<<endl;
cout<<"Enter Number of Clients That you want to ADD"<<endl;
cin>>n;
for(i=1; i<=n; i++)
{
cout<<"Please Enter Client Name :"<<endl;
getline(cin,w[5+i].name);
cin.get();
cout<<"Please Enter Client ID :"<<endl;
getline(cin,temp);
stringstream(temp)>>w[5+i].id;
cin.get();
cout<<"Please Enter Client INITIAL BALANCE :"<<endl;
getline(cin,temp);
stringstream(temp)>>w[5+i].balance;
cin.get();
}
cout<<endl;
cout<<"the new Record saved \3\3\3 thx \3\3\3"<<endl;
cout<<"\n"<<" (^__^)(^__^)\n"<<endl;
break;
case 2 :
cout<<"\n \2\2\2\2\2\2\2 Searching the Record \2\2\2\2\2\2\2 \n\n"<<endl;
break;
case 3 :
Actually it works for me... which compiler are you using?
Edit. Dunno, can't replicate the problem. As I said, the code works completely and prints " Entering Record" complete with the extra space on the left.
i use visual studio 2010
yes it works
but when the user enter the info
compilor dont put it on it's memory
and i find the loop looks for another time with out i enter which case i want
code works with u good ?
it dont do this ----> when the user enter the info
compilor dont put it on it's memory
and i find the loop looks for another time with out i enter which case i want
it's not works good :(( when i delete cin.get();
now it work please enter record name
and please enter record id together
it dont want to take the info
_________________ No one know the answer ?
what is cin.get(); do?
It reads a single character. In this case, we ignore the result, so cin.ignore() might be better, as the name better describes what we need.
After the user types some input in the keyboard, they press the "enter" key.
That stores all of the input, including a newline character, in the input buffer.
Some commands, such as cin>>n; will leave that newline sitting in the buffer.
When the next getline() is executed, it reads everything up to the newline as the required input. But because the very first character is a newline, the getline simply reads an empty string, and then moves on, meaning the user never even has a chance to type anything at all.
The solution is to remove any characters from the buffer before the getline. That's what the cin.get is for.