Hello,
I solved some exercises on the textbook called A First Book of ANSI C by myself and really happy about that. I have a major problem with one exercise. It says i have to use the (int) cast, devise a method to round the values in the variables a and b to the nearest hundredth (penny value) before they are added.
I have no idea what the question means!!! Any advice? I read a different book i brought from Korea to solve it in my own way but I dont know its right or not.
I tried to find solutions for the textbook but cant find it.
Question
Code:
double a, b, c;
a = 1.674;
b = 1.322;
printf("\n%4.2f",a);
printf("\n%4.2f",b);
printf("\n----");
c = a + b;
printf("\n%4.2f\n",c);
My code:
Code:
#include<stdio.h>
#include <math.h>
int main()
{
double a, b, c;
a = 1.674;
b = 1.322;
double round (double x);
a = round(a*100)/100;
b = round(b*100)/100;
printf("\n%4.2f",a);
printf("\n%4.2f",b);
printf("\n----");
c = a + b;
printf("\n%4.2f\n",c);
return 0;
}