Switch - Variables not being initialized.

Hello programmers, I am new to c++ and I'm currently taking a programming class at school.

I have this problem where I'm using multiple indented switch to calculate the values of two variables based on previously assigned variables, and at the end I get the error code that the two variables haven't been initialized yet. I know for sure that anything else before that part of my code work perfectly, it's been tested several times.

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
 switch(FormatPapier)
 {
	case 1:
	case 2:
	  switch(TypeImpression)
	  {
	        case 'R':
	          NbImpR = NbOri * NbExe;
		  NbImpRV = 0;
		  break;

		case 'V':
		 switch(NbOri % 2)
                   {
				default:
				  NbImpR = NbExe;
				  NbImpRV = (NbOri - 1) * NbExe / 2;
				  break;

				case 0:
				  NbImpR = 0;
				  NbImpRV = NbOri * NbExe / 2;
		   }
	  }
	  break;

	case 3:
	  switch(TypeImpression)
	  {
		case 'R':
		  switch(NbOri % 2)
		  {
			default:
			  NbOri = NbOri + 1;
			  NbImpR = NbOri * NbExe / 2;
			  NbImpRV = 0;
			  break;

			case 0 :
			  NbImpR = NbOri * NbExe / 2;
			  NbImpRV = 0;
		  }
		  break;

		case 'V':
		  Reste = NbOri % 4;
		  switch(Reste)
			{
				case 0:
				  NbImpR = 0;
				  NbImpRV = NbOri * NbExe / 4;
				  break;

				case 1:
				case 2:
				  NbImpR = NbExe;
				  NbImpRV = (NbOri - Reste) * NbExe / 4;
				  break;
				case 3:
				  NbImpR = 0;
				  NbImpRV = (NbOri + 1) * NbExe / 4;
			}
	  }
 }
cout <<NbImpR <<"    " <<NbImpRV;
_getch();


At the end, the variables NbImpR and NbImpRV turn out to be empty of any value, but I know for sure that the other variables NbOri, NbExe, FormatPapier and TypeImpression (the variables on which my equations to calculate NbImpR and NbImpRV are based on) do have values in them.

Can anybody spot where I might have gone wrong ? I am completely clueless as of now.
I am currently unable to access a computer, but I just thought of something.

The values of the variables FormatPapier and TypeImpression in my code are user inputs (previous option menus). To get those values I used _getche() (to echo the selection).

Since _getche() is used to put a character chain (if I remember correctly, correct me if I'm wrong) into a variable, should I write " case '1' " instead of "case 1"? Would that solve my problem, because it seems my program just skips over every switch for some reason?

Thanks.
Topic archived. No new replies allowed.