I feel so bad making another topic so soon after the other one. I was just wondering if there was something wrong with my if statements here. When I choose an option other than option 1,2, or 3 it works fine the program looks back and asks for another option to be inputted.
However when I input 1, 2, or 3 as the option, it's not working out.
The positive if commands seem to be working. When I select option 1 it prints option 1, however it then prints option 3 also. When I select option 2, it prints option 2 however it then prints option 3 also. If I select option 3, it continues in the while loop even though it should pass it by.
Hopefully this is just a small thing I've done wrong and quick to solve.
Alex
Code://A program that calculates the reduced mass of diatomic molecules. //The following libraries will be used. #include <stdio.h> #include <stdlib.h> #include <math.h> Manual_Input() { } Textfile_Input() { } int main() { int selection;//Defines the variable used to decide on a keyboard or text file input. while (selection!=1||selection!=2) { printf("A program to calculate the reduced mass of diatomic molecules.\n");//Intro Message. Data_input://Allows the program to loop if the user selects a value other than 1,2, or 3. printf("Input data from the keyboard, from a text\nfile, or close the program?\n"); printf("1. From the keyboard.\n");printf("2. From a text file.\n");printf("3. Close program.\n");printf(":"); scanf("%d",&selection);//Allows the user to choose whether or not to input from a text file or the keyboard. if (selection==1) { printf("Hello"); } if (selection==2) { printf("how are you?"); } if (selection!=1 || selection!=2 || selection!=3) { printf("Invalid Option, please choose again. "); } } return 0; }



LinkBack URL
About LinkBacks



