Hi,
I have a problem with a the imput of some data on a program Im making (FYI new in c++, homework).
So basicly the progrma I have is to imput diferent type of data, this is what im doing. (Im using codeblock 8.02 in Ubuntu 10.04 )
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <cmath>
using namespace std;
struct person
{
int cod;
char name[40], cid[15];
}client[100];
main()
{
int opc,exit serch, c=0, i, e;
while(exit!=1)
{
cout<<"1. Imput data"<<endl;
cout<<"2. Out data"<<endl;
cout<<"3. Exit"<<endl;
cout<<"Enter an opcion: "
cin>opc;
system("clear");
swith(opc)
{
case 1:
cout<<"Enter code: ";
cin>>client[c].cod;
cout<<"Enter name: ";
gets(client[c].name);
cout<<"Enter cid: ";
cin<<client[c].cid;
cout<<"Press enter to continue"<<endl;
getchar();
c++
system("clear");
break;
case 2:
cout<<"Enter code of the client: "
cin>>serch;
for(i=0;i<100;i++)
{
if(serch=client[i].cod)
{
cout<<client[i].cod;
cout<<client[i].name;
cout<<client[i].cid;
}
else
{
e=1;
}
}
if(e=1)
{
cout<<"Client does not exist"<<endl;
}
cout<<"Press enter to continue"<<endl;
getchar();
system("clear");
break;
case 3:
cout<<"Bye"<<endl;
exit=1
break;
default:
cout<<"Wrong option"<<endl;
break;
}
}
return 0;
}
Ok now the problem:
After I enter the code of the client (client[c].cod) it skips right away to ask for the client[c].cid skeeping the client[c].name imput, I was told to use gets so it will read spaces in a string, the work around I have done before is ask twice for the name:
cout<<"Enter name: ";
gets(client[c].name);
gets(client[c].name);
but I think that just a quick fix just so get an ok on the program, but is not what I should do, please help Im not sure what to do.