I'm not able to make a program where I need to input details(name, mobile number,
Date of birth) of 5 people & then user inputs the mobile number to get all the details of that person
You can use parallel arrays, each with a parallel indexing system and a single attribute per array, often a good start for beginners. Or you can use <vector>'s in a similar way. Or you can design a struct or class to encapsulate the attributes and array them in a single array or vector. or you could use a favourite - <map>'s or other STL container..
Some of those might not be familiar to you, so why not try parallel arrays? All the properties could be <strings>.
First of all thank you for your time ..
I tried using structures but failed
on output screen when it shows
"Enter your name : d " \\if I enter 1 character name it works fine.
but if I enter the proper name like Jack
the loop just displays all the couts.
plz try & help me by reference of a code..
THANK YOU
So, you've taken the slightly more challenging approach. Best thing to do is show us what code you have so we can taget our assistance to you. Otherwise you might get frustrated by us going over stuff you know. I'll keep an eye out for your code :)
Appreciate it ......
this code is just for input of details:-
#include<iostream.h>
#include<conio.h>
struct work
{int dob;
int mob;
char name;}
s[5][5];
void main()
{clrscr();
for(int i=0;i<5;i++)
{for(int j=0;j<5;j++)
{cout<<"Enter the name of candidate number "<<i+1;
cin>>s[i][j].name;
cout<<"Enter the dob of candidate number "<<i+1;
cin>>s[i][j].dob;
cout<<"Enter the mobile number of candidate number "<<i+1;
cin>>s[i][j].mob;}}
getch();}
#include <iostream>
#include <string>
struct work
{
std::string dob;
int mob;
std::string name;
};
constint limit = 3;
work s[limit];
int main()
{
for( int i = 0; i < limit; i++ )
{
std::cout << "Enter the name of candidate number " << i+1 << ' ';
std::cin >> s[i].name;
std::cout << "Enter the dob of candidate number "<< i+1 << ' ';
std::cin >> s[i].dob;
std::cout<<"Enter the mobile number of candidate number "<< i+1 << ' ';
std::cin>>s[i].mob;
}
for(int i = 0; i < limit; i++ )
std::cout << s[i].name << ' ' << s[i].dob << '\n';
return 0;
}
Hey Kemort......
the code you have given is showing errors like:-
5:type qualifier 'std' must be a struct or class name
5:declaration terminated incorrectly
and is same for
7,14,15,16,17,18,19,21
plz help
I think your error message relate to your system, being way out of date dare I say it. That's why I made the comments about conio etc and teaching machines. My code runs without error on my machine and, best for you since I can't give it to you as much as I would like, is the shell here. Just click on the gear whell in the right hand corner of my code above. i just double checked it and it works OK.
What you will need to do is modify my code to suit your environment or vice verso. I can't/won't use conio etc on/in my environment.
Your best option though is to understand what I did and see whether one or two pieces help you at all in your solution :)
Enter the name of candidate number 1 qwa
Enter the dob of candidate number 1 12/2
Enter the mobile number of candidate number 1 123
Enter the name of candidate number 2 rty
Enter the dob of candidate number 2 5/6
Enter the mobile number of candidate number 2 456
Enter the name of candidate number 3 fgh
Enter the dob of candidate number 3 9/0
Enter the mobile number of candidate number 3 890
qwa 12/2
rty 5/6
fgh 9/0
Exit code: 0 (normal program termination)