if/else syntax question

Good evening everyone.

The following is part of a code for a photocopy cost calculator program. I am having a hard time with the if/else part and I can't figure out what is wrong. The program reads a "paper format" input which is placed into FormatPapier. Prior to this, the user entered the number of pages for the original document and the the amount of copies wanted. The if/else part is to only output the "recto / recto-verso" option menu when the number of page on the original copy is higher than 1 or 2 (depending if the format chose was 8x11 or 11x17). If that value equals 1 or 2, the recto option is automatically put into the corresponding variable.

Unfortunately, the program won't go past the if line, so something must be wrong with my condition but I can't figure it out. Am I missing something blatantly obvious, or what ? Thanks !
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
 //Lecture du format de papier 
			gotoxy(0,4);
			cout <<"Format du papier:\n";
			cout <<setw(L1) <<left <<"";
			cout <<"1. 8\xabx11\n";
			cout <<setw(L1) <<left <<"";
			cout <<"2. 8\xabx14\n";
			cout <<setw(L1) <<left <<"";
			cout <<"3. 11x17\n\n";
			cout <<setw(L1) <<left <<"";
			cout <<"Votre choix: ";
			FormatPapier = _getche();

		//Exceptions
			if(((FormatPapier == 1 || FormatPapier == 2) && NbOri >= 2) || ((FormatPapier == 3) && NbOri ­­>= 3))
			{
				//Lecture du type d'impression
				gotoxy(0,11);
				cout <<"Type d'impression:\n";
				cout <<setw(L1) <<left <<"";
				cout <<"R. recto\n";
				cout <<setw(L1) <<left <<"";
				cout <<"V. recto/verso\n\n";
				cout <<setw(L1) <<left <<"";
				cout <<"Votre choix: ";
				TypeImpression = _getch();
				TypeImpression = toupper(TypeImpression);
				cout <<TypeImpression;
			}
			else
			{
				TypeImpression = 'R';
			}
Last edited on
I do not know what your program is supposed to do, but when things are not working I like to place checkpoints in parts of the code. This way I see where it goes or does not go.
For example.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
cout << "START OF IF\n";
if(myBoolStatement)
{
    cout << "#\n";
    doSomthing();
}
else if(otherBoolStatement)
{
    cout << "$\n";
    doSomthingElse();
}
else
{
    cout << "*\n";
    giveUp();
}

cout << "END OF IF\n";

Now if I know 100% this set if input should run doSomthingElse(), and it does not, I can see what happens instead. This method solved so much logic errors for me. So try adding a few of these, see what your code produces, and find those annoying logic errors.
Line 1 to 12 is where the user is supposed to choose what paper format they'd like their photocopies printed on.

Line 17 to 28 is the second menu where the user picks recto or recto-verso printing.

The if on line 15 is to make sure the recto-verso menu is not showed in the cases that:
a) The paper format chosen is 8x11 or 8x14 AND the original document only has one page (for obvious reasons)
b) The paper format chosen is 11x17 and the original document has either 1 or two pages. (Because it is assumed that the original is 8x11 and you can fit two pages on one 11x17)

Thanks for the checkpoints tip, I will certainly use it when needed. I just realized that, since I used _getche() to put a value into FormatPaper, I need to use ' ' in my condition statement.

I've modified my code and it seems to be working, but feel free to add anything else that could help improve or stabilize it.
Topic archived. No new replies allowed.