-3
case'1':
{
... // case 1 will require you to input a ID number and a bunch of info..
break;
}

case'2':
{
...// case 2 is gonna search the ID and display the info
break;     
}

the result would something like..

Whats your choice :1

Enter a ID no. : 0001 //USER is ask to make a ID number
Enter Name : Paolo    //USER is ask to enter a Name
Enter Address: blah blah //USER is ask to enter an address

...Then if all the input is filled it will go back to the menu.

whats your choice :2 
Enter ID : 0001  //User is ask to enter the ID number he created
Name : paolo   // DISPLAY THE NAME 
address : blah blah //DISPLAY THE ADDRESS

EDIT: REVISED my question can the switch statement do it.?

user3352725
  • 3
  • 1
  • 1
  • 4
  • Break after each case. Check out this : http://stackoverflow.com/questions/188461/switch-statement-fallthrough-should-it-be-allowed – Kissiel Feb 25 '14 at 21:09
  • The switch section goes into this in detail: http://www.cplusplus.com/doc/tutorial/control/ – Zac Howland Feb 25 '14 at 21:10
  • Are you asking how to store the data in an array maybe? – Mooing Duck Feb 25 '14 at 21:10
  • sounds like homeworks. italian homeworks. – rano Feb 25 '14 at 21:10
  • 2
    Ok, so he didn't forget to break. Then it's just unclear. – KeatsPeeks Feb 25 '14 at 21:11
  • @MooingDuck exactly we havent covered the storing of data using files..its something like as long as you dont close the program it can still store the inputs and read them again with the search function – user3352725 Feb 25 '14 at 21:13
  • Have you learned about [structs/classes](http://www.cplusplus.com/doc/tutorial/structures/) or [vectors](http://www.cplusplus.com/reference/vector/vector/)? – jliv902 Feb 25 '14 at 21:15

2 Answers2

1

In C, you'd need an array of Person structures. For example:

typedef struct
{
    char name[MAX_NAME];
    char address[MAX_ADDRESS];
} person;

person people[MAX_PEOPLE];

I'm no C++ expert however, so there's probably a better way.

Fiddling Bits
  • 8,712
  • 3
  • 28
  • 46
  • 2
    `struct person {std::string name; std::string address;}; std::vector people;` but pretty much the same concept. – Mooing Duck Feb 25 '14 at 21:17
0

As i understood from 'how can i make several ID and info input without replacing the first one'. you should store info, associated with each id, in special array (std::map for ex.).

#include <map>
#include <string>
#include <iostream>

using namespace std;

struct IdInfo {
    string name;
    string address;
};

int main() {

std::map<std::string, IdInfo> idsInfo;

while (true) {
    cout << "\ninput 1 or 2:";
    char input = (int)getchar();
    cin.get();
    switch (input) {
    case '1': {
        cout << "\nwrite id:";
        std::string id;
        getline(cin, id);
        cout << "\nwrite name:";
        std::string name;
        getline(cin, name);
        cout << "\nwrite address:";
        std::string address;
        getline(cin, address);
        IdInfo newInfo;
        newInfo.name = name;
        newInfo.address = address;
        idsInfo[id] = newInfo;
    break;}
    case '2': {
        std::string id2;
        cout << "\nwrite id:";
        getline(cin, id2);
        IdInfo info = idsInfo[id2];
        std::cout << "\ninfo:" << info.name << " " << info.address;

    break;}
    default:
       // Finish execution.
       return 0;
    break;
    }
}

}
str14821
  • 243
  • 1
  • 10
  • Not quite what it.. in case'1' the user is ask to enter details and in case'2' it will reveal the details via searching for the id the user also created – user3352725 Feb 25 '14 at 21:30
  • You can promt and read needed data in this way: std::cout << "\nEnter id:"; std::string id; std::getline(std::cin, id); – str14821 Feb 25 '14 at 21:38
  • then what if i wanted to add another id but still keep the first id entered ._. – user3352725 Feb 25 '14 at 21:44
  • As u can see, I store all id info in std::map. I changed code a bit so now u can try to compile it and run. Compile it, run, enter 1: then enter id, name and address. After it enter 1 again and enter other id, name, address. After it enter 2. now enter first id. You ll get all info that you have entered first. Now enter 2 and then second id. You'll get info associated with it. – str14821 Feb 25 '14 at 21:49
  • i just compile it gave me 97 warnings..run it case'1' works then program goes coco – user3352725 Feb 25 '14 at 22:03
  • 'coco' what? After case '1' finished u will be asked to enter choice again. You can enter 2 then and after it enter id that you have entered on step 1. In this way you can add multiple ids and all its data will be stored in memory (via idsInfo) Just try it. – str14821 Feb 25 '14 at 22:12