Add up decimals
Is there any way i can the compiler to add decimal numbers number that the user input.
if user put in 156.7, 76.4, and 54.1 how can i make a program that will add the 7 the 4 and 1 together.
This should help, this code snippet would output 0.7
1 2 3 4 5 6 7 8 9 10 11
|
int main()
{
double num1;
num1 = 156.7;
double integral;
double fractional = modf(num1, &integral);
cout << fractional;
}
|
if you wanted to make it a whole number you could do something like
fractional *= 10;
1 2 3 4 5 6 7 8 9 10 11 12
|
int main()
{
double num1;
num1 = 156.7;
double integral;
double fractional = modf(num1, &integral);
fractional *= 10;
cout << fractional;
}
|
Topic archived. No new replies allowed.