1
Once I enter the variable data originalMoney
the prompt crash.
Follow the code (it’s incomplete, I only ran the test with the first case
)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int main()
{
float coinsValue, notesValue, totalMoney;
int switchValue;
char originalMoney, convertedMoney;
printf("Enter original money type\n");
scanf("%c",&originalMoney);
printf("Enter the type of money you want to convert\n");
scanf("%c",&convertedMoney);
if (strcmp(originalMoney, "REAL") == 0 && strcmp(convertedMoney, "DOLLAR") == 0){
switchValue = 1;
} else if (strcmp(originalMoney, "REAL") == 0 && strcmp(convertedMoney, "LIBRAS")){
switchValue = 2;
} else if (strcmp(originalMoney, "DOLLAR") == 0 && strcmp(convertedMoney, "REAL")){
switchValue = 3;
} else if (strcmp(originalMoney, "DOLLAR") == 0 && strcmp(convertedMoney, "LIBRAS")){
switchValue = 4;
} else if (strcmp(originalMoney, "LIBRAS") == 0 && strcmp(convertedMoney, "REAL")){
switchValue = 5;
} else if (strcmp(originalMoney, "LIBRAS") == 0 && strcmp(convertedMoney, "DOLLAR")){
switchValue = 6;
} else {
printf("You have chosen an invalid conversion option!");
}
switch (switchValue) {
case 1:
printf("Entering case 1...\n");
printf("Enter coins value in R$: \n");
scanf("%f",coinsValue);
printf("Enter notes value in R$: \n");
scanf("%f",notesValue);
totalMoney = coinsValue + notesValue;
totalMoney = totalMoney * 4.01;
printf("The value in reais converted to dollar is: %.2f",totalMoney);
break;
case 2:
printf("Entering case 2...\n");
break;
case 3:
printf("Entering case 3...\n");
break;
case 4:
printf("Entering case 4...\n");
break;
case 5:
printf("Entering case 5...\n");
break;
case 6:
printf("Entering case 6...\n");
break;
}
return 0;
}
Problem is that you are trying to put a string in a single character, it will never work in C
– Andre Lacomski
I get it, thank you!
– user143767
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site
– Maniero