how can i Write a C++ program to display cities of USA using switch case
newyork,virginia,texas,hollywood,chicago & newmexico

Recommended Answers

If you display a list and allow the user to choose one city using a integer input. I'm not sure if you can use a string in a Switch-statement... C++11 might allow you to, but nothing older.

The list would look something like this:

#include <iostream>

using namespace std; …
Jump to Post

All 4 Replies

Member Avatar

If you display a list and allow the user to choose one city using a integer input. I'm not sure if you can use a string in a Switch-statement... C++11 might allow you to, but nothing older.

The list would look something like this:

#include <iostream>

using namespace std;

int main(void){
    int Input;
    char List[] = "States: "
                  "\n\t1 - Virginia "
                  "\n\t2 - Texas ";

    cout << List << endl;
    cin >> Input;

    switch(Input){
        case 1:  //insert your own code here
            break;
        case 2:  //and here
            break;
        default:   //and here
            break;
    }

    return 0;
}

how can i Write a C++ program to manipulate string function using 12 condition

#include <iostream>

using namespace std;

int main(void){
    int Input;
    char List[] = "States: "
                  "\n\t1 - Virginia "
                  "\n\t2 - Texas ";

    cout << List << endl;
    cin >> Input;

    switch(Input){
        case 1:  //insert your own code here
            cout << "Virginia" << endl;
            break;
        case 2:  //and here
            cout << "Texas" << endl;
            break;
        default:   //and here
            break;
    }

    return 0;
}

if array value is too small.
explain code like this. too simple.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.