Switch Statement Void Problem

Hello everyone. Whenever I pick a number in my code and enter the input below, the "cout << Your Personality is ..... " sentence doesn't print. What seems to be the problem in my code below?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

void A () { //main menu
  cout << "\t\t\v\vWhat Kind of Personality Do You Have?" << endl;
  cout << "\t\t1: Overview" << endl;
  cout << "\t\t2: Openess" << endl;
  cout << "\t\t3: Extraversion" << endl;
  cout << "\t\t4: Agreeableness" << endl;
  cout << "\t\t5: Neuroticism." << endl;
  cout << "\nPick a number: ";
}

void P1 () {
    cout << "Your Personality is Openness." << endl;
}

void P2 () {
    cout << "Your Personality is Openess." << endl;
}

void P3 () {
    cout << "Your Personality is Extraversion." << endl;
}

void P4 () {
    cout << "Your Personality is Agreeableness." << endl;
}

void P5 () {
    cout << "Your Personality is Neuroticism." << endl;
}

 int main () {
  
 char q;
  int picked;
  A ();
  cin >> picked;
  switch (q) {
      
      case '1':
      P1 ();
      break;
      
      case '2':
      P2 ();
      break;
      
      case '3':
      P3 ();
      break;
      
      case '4':
      P4 ();
      break;
      
       case '5':
      P5 ();
      break;
  }
  
   
    
    
    return 0;
}
Last edited on
Well, you input "picked" and you switched on the basis of "q".

Apart from the fact that they clearly aren't the same variable, you haven't made up your mind whether you are inputting ints or chars.

BTW. Have you heard about arrays? They would save you from switch statements and multiple tiny functions here.
Last edited on
Oh, I see so that's why it doesn't print. Thanks, man. I highly appreciate that.
Last edited on
Topic archived. No new replies allowed.