-3

I am new at C programming, so I am trying to make the user to calculate certain things using switch statement, the problem is that the result doesn't show on the program, for example if I enter 1 and enter the 50*6.63, the result is empty.

#include <stdio.h>
#include <stdlib.h>

int main()
{
    float Str;
    float bonusArmor;
    float Haste;
    float Crit;
    float Multi;
    float Vera;
    float Mas;
    float result;
    int option;
    printf("Press 1 for Strength\n");
    printf("Press 2 for Bonus Armor\n");
    printf("Press 3 for Haste\n");
    printf("Press 4 for Critical Strike\n");
    printf("Press 5 for Multistrike\n");
    printf("Press 6 for Versaility\n");
    printf("Press 7 for Mastery\n");
    scanf("%d", &option);


    switch(option){

        case 1:
            printf("Enter Strength:\n");
            scanf("%f", &Str);
            result = (6.63*Str);
            printf("Total is: ", result);
            break;

        case 2:
            printf("Enter Bonus Armor:\n");
            scanf("%f", &bonusArmor);
            result = 6.30*bonusArmor;
            printf("Total is: ", result);
            break;

        case 3:
            printf("Enter Haste:\n");
            scanf("%f", &Haste);
            result = 3.66*Haste;
            printf("Total is: ", result);
            break;

        case 4:
            printf("Enter Critical Strike:\n");
            scanf("%f", &Str);
            result = 3.57*Str;
            printf("Total is: ", result);
            break;

        case 5:
            printf("Enter Multistrike:\n");
            scanf("%f", &Str);
            result = 3.18*Str;
            printf("Total is: ", result);
            break;

        case 6:
            printf("Enter Versatility:\n");
            scanf("%f", &Vera);
            result = 2.63*Vera;
            printf("Total is: ", result);
            break;

        case 7:
            printf("Enter Mastery:\n");
            scanf("%f", &Mas);
            result = 2.49*Mas;
            printf("Total is: ", result);
            break;

        default:
            printf ("Invalid input");

    }

    return 0;
}
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Hghi
  • 11
  • 1
  • 3
  • To receive an answer to your question try to a) make the title better represent your problem and b) give a *minimal* code snippet. – Stefan van der Walt Feb 03 '15 at 01:12
  • 1
    Why do you enter 50*6.63, you're already multiplying with 6.63 in switch statement. 50*6.63 is a string. –  Feb 03 '15 at 01:12
  • 1
    You need to check how to use [`printf()`](http://www.cplusplus.com/reference/cstdio/printf/). – SSC Feb 03 '15 at 01:15
  • Make sure you add a newline to the end of a `printf()` statement or the output may not appear for a long time. It's also usually considered to be a good idea to add a `break;` after every case in a `switch` statement). – Jonathan Leffler Feb 03 '15 at 01:18

2 Answers2

0

You need to print floats like:

printf("Result is: %.2f", result);

Look here for a bit more information

Community
  • 1
  • 1
jnd
  • 754
  • 9
  • 20
0

You must specify a conversion specification to print a value:

printf("float: %f\n", floatValue);

The newline ensures the output appears when you print.

#include <stdio.h>
#include <stdlib.h>

int main()
{
    float Str;
    float bonusArmor;
    float Haste;
    float Crit;
    float Multi;
    float Vera;
    float Mas;
    float result;
    int option = 0;
    printf("Press 1 for Strength\n");
    printf("Press 2 for Bonus Armor\n");
    printf("Press 3 for Haste\n");
    printf("Press 4 for Critical Strike\n");
    printf("Press 5 for Multistrike\n");
    printf("Press 6 for Versatility\n");
    printf("Press 7 for Mastery\n");
    scanf("%d", &option);

    switch(option){

        case 1:
            printf("Enter Strength:\n");
            scanf("%f", &Str);
            result = (6.63*Str);
            printf("Total is: %f\n", result);
            break;

        case 2:
            printf("Enter Bonus Armor:\n");
            scanf("%f", &bonusArmor);
            result = 6.30*bonusArmor;
            printf("Total is: %f\n", result);
            break;

        case 3:
            printf("Enter Haste:\n");
            scanf("%f", &Haste);
            result = 3.66*Haste;
            printf("Total is: %f\n", result);
            break;

        case 4:
            printf("Enter Critical Strike:\n");
            scanf("%f", &Str);
            result = 3.57*Str;
            printf("Total is: %f\n", result);
            break;

        case 5:
            printf("Enter Multistrike:\n");
            scanf("%f", &Str);
            result = 3.18*Str;
            printf("Total is: %f\n", result);
            break;

        case 6:
            printf("Enter Versatility:\n");
            scanf("%f", &Vera);
            result = 2.63*Vera;
            printf("Total is: %f\n", result);
            break;

        case 7:
            printf("Enter Mastery:\n");
            scanf("%f", &Mas);
            result = 2.49*Mas;
            printf("Total is: %f\n", result);
            break;

        default:
            printf("Invalid input\n");
            break;
    }

    return 0;
}
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278