0

Hi everyone I am new to C, I have only started to learn and practice it 2 days ago, and I am trying to write my first program, which is a currency converter. I have nailed the first part, but in the if statement part of the code, it seems to be failing. I am trying to test my code by putting in the input I want and even though the condition of the if statement is met, the code in it is not activating. Any help would be appreciated.

#include <stdio.h>

int main() 
{
   char currency[3];
   printf("What is your currency? (can only be USD or AED)\n");
   scanf("%s", currency);
   if (currency == "USD") {
       printf("How many dollars are you converting?\n");
       int money;
       scanf("%d", &money);
       long finalResult;
       finalResult = money*3.67;
       printf("You have %ld",finalResult);
   }
   

}
  • 1
    Comparing two pointers for equality compares the pointers, not that to which they point. – ikegami May 11 '22 at 00:44
  • Be careful with buffer overflow in C. You may want `currency` to be an array of `4` instead of `3` characters because `scanf()` adds null terminating character. Read about `scanf()` documentation and check its return value as well in your program. – H.S. May 11 '22 at 00:47

0 Answers0