0

In below code, it doesn't start entry with the "name function" if I use it inside switch/if statement?! it starts with the second function "age". But if I use it outside switch/if statement, it works fine. Why?!

#include <iostream>

using namespace std;

void name(){

    char name[20];      
    cout << "Name: ";
    cin.getline(name,20); 
 
}
void age (){

    char age;
    cout << "Age: ";
    cin >> age;
 
}

int main (){

int choice;

    cout << "Enter choice (1/2): ";
    cin >> choice;

switch(choice){
        
        case 2:

            cout << "Something else here...";
            break;

        case 1:

            cout << "Only Name and Age\n";
            name();
            age();
            break;
    }
            
}
Devolus
  • 20,356
  • 11
  • 56
  • 104
sqluser
  • 313
  • 1
  • 3
  • 17

0 Answers0