A weird switch issue

here is my code:
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
#include "stdafx.h"

#include "profileClass.h"
#include "Gun1.h"
#include "Gun2.h"
#include "Gun3.h"

#include <iostream>
#include <string>


using namespace std;

int choice;

int main( void ){

	profile profile;
	
	cout << "Enter your desired profile name (no spaces): ";
	cin >> profile.Name;
	cout << endl << profile.Name << ", select your gun: " << endl;
	cout << "\t1. Tech 9" << endl << "\t2. Magnum" << endl << "\t3. Sawed Off" << endl << endl;
	cin >> profile.GunId;
	cout << endl << "loading..";

	switch( profile.GunId ){
	case '1': profile.GunName = "Tech 9"; break;
	case '2': profile.GunName = "Magnum"; break;
	case '3': profile.GunName = "Sawed Off"; break;
	default: profile.GunName = "N/A - you didnt pick a valid gun";
	}

	getchar();

	system("cls");

	cout << "Profile Information:" << endl;
	cout << "\tName: " << profile.Name << endl;
	cout << "\tGun ID: " << profile.GunId << endl;
	cout << "\tGun Name: " << profile.GunName << endl;

	cout << endl;
	return 0;
}


in my switch statement.. it always executes the default case and I dont know why. profile.GunId IS equal to something... i have tested it. after system("cls"), profile.GunId is equal to 1, 2 or 3, but profile.GunName is equal to the N/A string. If you know whats going on here, please let me know, i thank in advance for any helpers. later.
closed account (z05DSL3A)
If profile.GunId is an int use:

1
2
3
4
5
6
switch( profile.GunId ){
	case 1: profile.GunName = "Tech 9"; break;
	case 2: profile.GunName = "Magnum"; break;
	case 3: profile.GunName = "Sawed Off"; break;
	default: profile.GunName = "N/A - you didnt pick a valid gun";
	}


case '1' would be a char 1
Last edited on
Topic archived. No new replies allowed.