my_var = (int)my_var;
As simple as that. Basically you don't need it if the variable is int.
Answer from Zach P on Stack OverflowInteger division truncates, so (50/100) results in 0. You can cast to float (better double) or multiply with 100.0 (for double precision, 100.0f for float precision) first,
double percentage;
// ...
percentage = 100.0*number/total;
// percentage = (double)number/total * 100;
or
float percentage;
// ...
percentage = (float)number/total * 100;
// percentage = 100.0f*number/total;
Since floating point arithmetic is not associative, the results of 100.0*number/total and (double)number/total * 100 may be slightly different (the same holds for float), but it's extremely unlikely to influence the first two places after the decimal point, so it probably doesn't matter which way you choose.
integer division in C truncates the result so 50/100 will give you 0
If you want to get the desired result try this :
((float)number/total)*100
or
50.0/100
How do I cast my int to float?
Converting int to float in C function - Stack Overflow
convert float to integer - C++ Forum
Does C allow implicit casting/conversion from float to an int?
Can float to int conversion be done using functions in C?
Can you convert float to int without losing data?
Which function is used to round off a float before converting to int?
Videos
int main (void)
{
string text = get_string("Text: ");
int Letters = count_letters(text);
int words = count_words(text);
int sen = count_sen(text);
int L = (100/words) * Letters;
int S = (100/words) * Letters;
int index = 0.0588 * L - 0.296 * S - 15.8;
int index1 = round(index);
printf("%i\n", Letters);
printf("%i\n", words);
printf("%i\n", sen);
printf("%i\n", index1);
}