I've searched the forums, and I can't seem to find an answer that is suitable for my specific problem (I tried Google as well). I seem to be having an issue comparing the strings ("Yes", "yes", "No", "no") correctly. I tried an if else originally, but I think a while loop is more efficient. Any suggestions?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
double far = 0;
double cel = 0;
double userValue = 0;
double endResult = 0;
int choice;
char *decision = "";
int main()
{
conversion();
return 0;
}
conversion() {
printf("Please enter a 1 for Celsius to Fahrenheit conversion OR\n a 2
for
Fahrenheit to Celsius conversion\n");
scanf("%d", &choice);
if(choice == 1) {
printf("Please enter a value for Celsius. Example 32 or 32.6\n");
scanf("%lf", &userValue);
endResult = (userValue * (9.0/5.0) + 32);
printf("%lf\n", endResult);
yesOrNo();
}
else
printf("Please enter a value for Fahrenheit. Example 212 or 212.6\n");
scanf("%lf", &userValue);
endResult = (userValue -32) * (5.0/9.0);
printf("%lf\n", endResult);
yesOrNo();
}
yesOrNo() {
printf("Do you want to continue? Enter Yes or No\n");
scanf(" %s", &decision);
while(decision == "Yes" || decision == "yes") {
conversion();
}
exit(0);
}