I am attempting to create a boolean flag that will output an error message when an invalid input code is entered. This is for a class assignment and I am just learning C so please forgive the formatting and notify me if it could be improved. I have the code doing everything successful except for outputting the error message if the input or output variables are incorrect. I believe this is an error with the boolean check part of the code. A diagnosis would be great.
This code will:
- request and source currency, destination currency, and source amount
- output the destination currency amount or error message if the input variables are incorrect
Parameters:
- the source and destination currency must be Canadian dollars ($), Yen (Y), or Euros (E)
- a boolean flag must be used
Thanks in advanced.
# include <stdio.h>
int main() {
char $ = $;
char Y = Y;
char E = E;
char in_currency, out_currency;
char flag = 1;
char new_line;
float in_value;
float out_value;
//Calculation variables
printf("Enter the source currency: ");
scanf("%c%c", &in_currency, &new_line);
printf("Enter the destination currency: ");
scanf("%c%c", &out_currency, &new_line);
if ( ( in_currency || out_currency ) != ( '$' || 'Y' || 'E' ) )
flag = 0;
printf("Enter the value: ");
scanf("%f%c", &in_value, &new_line);
//Calculations
if (flag) {
printf("%c%.2f = %c%.2f \n", in_currency, in_value, out_currency, out_value);
}
else {
printf("There was an error with the input. \n");
}
return 0;
}