#include <iostream>
#include <conio.h>
#include <string.h>
#include <stdio.h>
usingnamespace std;
class caste{
char name[100];
char achieve[500];
int rank;
public:
void getinfo(){
cout<<"Enter Name :";
gets(name);
}
void geta()
{cout<<"Enter Achive :";
gets(achieve);}
void getr(){
cout<<"Enter rank :";
cin>>rank;}
};
int main()
{caste khan[10];
for(int i=0;i<5;++i)
{cout<<"Enter info about Khan no. "<<i<<" now : ";
khan[i].getinfo();
khan[i].geta();
khan[i].getr();
}
return 0;
}
the problem is that after 1st member(khan) information is entered thn afterards it starts skipping the "name" part of every remaining member.
It just asks for achievement and rank.
any help ? btw i use visual c++ 2010
Line 21 reads the next integer and leaves everything after the int string untouched. That means that if you enter a number and press enter it only reads the number but the new line character is still there. gets reads until it finds a new line character so when you call gets the next time it will find the new line character that was left over right away making the string empty. One way to solve this is to place something like std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); after cin>>rank;. What this ignore call is doing is that it discards everything until it finds the new line character. The new line character is discarded too so this will place you on a new fresh line.