-
aligning decimal points?
Im new to c programing and am in a class to learn.
our first project we have to create a program that allows a user to input their time worked hours pays and a deduction and then have the program display all their taxes and gross / net pay.
that much I have done but for full credit we must make all the decimal points line up. what would be the best way to do this?
-
Use the format specifiers for printf(). In particular the field width and resolution specifications:
Code:
printf("%10.2f\n",1234.5);
printf("%10.2f\n",67.89);
Makes a fleld 10 digits wide (the dot counts as 1 width), and displays your floating point number to 2 decimal places. You can change the position of the numbers inside the field width, by using the - before the field width specifier: %-10.2f etc.
-
yeah adak was right
u can doing this on int and other declaring variables too
like this
Code:
int a,b;
char c,*d;
float e;
printf("%10d",a);
printf("%10i",b);
printf("%10c",c);
printf("%10.1f",e);
printf("%10s",d);