D
Deleted User
Guest
OP
So I'm trying to learn c, and trucking along rather nicely, when WHAM, huge fucking truck in the name of if/else.
Below is my attached code.
It should be
1) if 1, AC turned on.
2) if 2, AC turned off.
3) if anything else, incorrect key.
But what's happening is that 2) & 3) are working perfectly normal, but when I use 1...
the text for both conditions 1) & 3) appear at the same time! And I can't understand why!
Maybe someone can point it out to me what I'm doing wrong. I've been here trying different solutions and googling to try and learn myself, so I come and beg the question itself.
If I'm in the wrong forum section, please feel free to alert a moderator and/or have it moved to the correct section.
Thanks in advanced.
Below is my attached code.
It should be
1) if 1, AC turned on.
2) if 2, AC turned off.
3) if anything else, incorrect key.
But what's happening is that 2) & 3) are working perfectly normal, but when I use 1...
the text for both conditions 1) & 3) appear at the same time! And I can't understand why!
Maybe someone can point it out to me what I'm doing wrong. I've been here trying different solutions and googling to try and learn myself, so I come and beg the question itself.
If I'm in the wrong forum section, please feel free to alert a moderator and/or have it moved to the correct section.
Thanks in advanced.
Code:
//Learning if statements!
#include <stdio.h>
int main () {
int iresponse = 0;
printf("\nAc Control Program.\nPlease chose an option.\n[1] to turn on the AC system.\t[2] to turn off the AC system.");
scanf("%d", &iresponse);
if (iresponse == 1){
printf ("\nThe AC system is now off!\nThis system will now go into standby mode."); //end 1
}
if (iresponse == 2){
printf ("\nThe AC system is now off!\nThis system will now go into standby mode."); //end 2
}
else
printf ("\nIncorrect key. Shutting down."); //end else
}//end main