tags:

views:

92

answers:

1

Hi. I'm practising with C, writing simple programs. The little program below should just get 3 numbers from the user and multiplicate them. My problem is that i'm a bit confused about the variable type i must use. I want the program to take any number such as 5, 5.673434, 99.123 and so, calculate with them and print out a rounded float number. I have tried many things out but sincerly the result is always false. The program just prints out really big numbers and confusing character sequences. I would be thankful for any advise. Thank you.

#include <stdio.h>

int main()
{
    int num1, num2, num3;

    printf("Hello! This little programm will execute a few calculations \nafter you've typed in 3 numbers of your choise. \nPlease type in your first number: ");
    scanf_s("%f", &num1);
    printf("Great. Please choose your second number: ");
    scanf_s("%f", &num2);
    printf("And the third number please: ");
    scanf_s("%f", &num3);
    printf("Ok. You want to use %f, %f, %f for your calculation. Press a button begin.\n", num1, num2, num3 );  
    printf("Multiplication: %.2f", num1 * num2 * num3); 

    getchar();
    getchar();
    return 0;
}
+13  A: 

You need to declare the variables as float

float num1, num2, num3;
codaddict
Thank you. It works well.
Ordo