Using the Switch Statement in C++

... // case 1 will require you to input a ID number and a bunch of info..

...// case 2 is gonna search the ID and display the info

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.?


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.

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();
    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; = name;
        newInfo.address = address;
        idsInfo[id] = newInfo;
    case '2': {
        std::string id2;
        cout << "\nwrite id:";
        getline(cin, id2);
        IdInfo info = idsInfo[id2];
        std::cout << "\ninfo:" << << " " << info.address;

       // Finish execution.
       return 0;


Need Your Help

C : converting binary to decimal


Is there any dedicated function for converting the binary values to decimal values.

Binding Rich Text Box ScaleTransform to slider inside User Control

c# wpf xaml data-binding

I have an instance of a user control in my project that contains a slider. I would like to bind the ScaleTransform of a RichTextBox control to the value of the slider but I do not know how to prope...