0

So, here is the code:

#include <stdio.h>

int main (int argc, char **argv)
{
    float num;

    printf ("Choose one: 1.2 or 2.4 or 3.6 or 4.8: ");
    scanf ("%3f",&num);
    printf("\nTEST = %f\n",num);

    if (num == 1.2)
        printf("\n you selected the first (1.2)\n");

    if (num == 2.4)
        printf("\n you selected the secon (2.4)\n");

    if (num == 3.6)
        printf("\n you selected the third (3.6)\n");

    if (num == 4.8)
        printf("\n you selected the fourth (4.8)\n");

    return 0;
}

It's just a simple assignment, I can use only if, can't use else, but the code simply refuses to work. I wrote it with Gedit and compiled with GCC (ubuntu). Already tested with CodeBlocks, Dev-C++ (Windows 8) and CppDroid (Android). The problem is that none of the IFs seem to work and show the 'printf', what am I doing wrong?

John Odom
  • 1,189
  • 2
  • 20
  • 35

0 Answers0