int years = 0;
double rate, investment;
printf ("Principal :");
scanf("%f", &investment);
printf ("Rate :");
scanf("%f", &rate);
double total = investment;
while (total < investment * 2)
{
total = total * (1 + rate);
years += 1;
}
printf("%d years";
return 0;
Why can't I print it out because the years repetition is applied within the while statement?
c scanf
The format character for reading the float variable in scanf is "%f"
, but you must use "%lf"
to read the double variable.
© 2024 OneMinuteCode. All rights reserved.