0
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void  passEurosToDollars()
{
    char election;
    int quantity;
    float change = 0.9;
    while (1)
    {
        printf("Put D to pass Euros to Dollars or put E to pass Dollars to Euros: ");
        scanf("%c", &election);

        if(election == 'd' || election == 'D')
        {
            printf("Enter quantity to change: ");
            scanf("%i", &quantity);

            printf("The result is %f Dollars", quantity / change);
            break;
        }

        else if (election == 'e' || election == 'E')
        {
            printf("Enter quantity to change: ");
            scanf("%i", &quantity);

            printf("The result is %f Euros", quantity * change);
            break;
        }

        else
        {
            printf("Wrong election\n");
        }
    }
}

int main()
{
    passEurosToDollars();
    return 0;
}

When I try to put a letter that it hasn't got any option, it may be output an error and again the input. It's very strange, I tried change it to array[3] with 3 of length and with getchar. The compiler used is gcc. enter image description here

Barmar
  • 741,623
  • 53
  • 500
  • 612

0 Answers0