Saturday, August 29, 2020

float.c : get a floating point number from the user

#include <cs50.h>
#include <stdio.h>

int main(void)
{

float price = get_float("what is the price?\n");

printf("the price plus tax is %f\n", price*1.0625);

}


limit the output to 2 digits after the decimal point:

#include <cs50.h>
#include <stdio.h>

int main(void)
{

float price = get_float("what is the price?\n");

printf("the price plus tax is %.2f\n", price*1.0625);

}



[Source: harvard, cs50]

No comments:

Post a Comment