# 'Type double' help D:

This is a discussion on 'Type double' help D: within the C Programming forums, part of the General Programming Boards category; I'm doing an assignment for an Intro to C class and one of the problems assigned from the book requires ...

1. ## 'Type double' help D:

I'm doing an assignment for an Intro to C class and one of the problems assigned from the book requires me to:

-Write a program that prompts the user to enter three numbers
-Prints the three numbers vertically, first forward and then reversed.

Simple enough, my code for that is
Code:
```#include <stdio.h>

int main()
{
// Local Declarations
int a, b, c;

// Statements
scanf("%d %d %d", &a, &b, &c);

printf("\n\nYour numbers forward: \n%d \n%d \n%d\n\n", a, b, c);
printf("Your numbers reversed: \n%d \n%d \n%d", c, b, a);

return 0;

}```
and the output is what I thought was required...
7 77 777

7
77
777

777
77
7
I look back at the HW requirements and it turns out for this particular problem, my professor wants me to write more stuff; "Declare the three numbers of type double. Format the output: xxx.xx (such as 200.99, 50.25, etc.)."

Don't really have any idea on what to do for this... I changed the int to double but my output gets really weird.

This is the new code (with int changed to double)
Code:
```#include <stdio.h>

int main()

{
// Local Declarations
double a, b, c;

// Statements
scanf("%d %d %d", &a, &b, &c);

printf("\n\nYour numbers forward: \n%d \n%d \n%d\n\n", a, b, c);
printf("Your numbers reversed: \n%d \n%d \n%d", c, b, a);

return 0;

}```
This is the output with said-new code
5 10 15

5
4200358
10

15
1988563298
10
Some advice would be greatly appreciated :X

2. Ah well, after reading some older threads, I changed some of the code:

Code:
```#include <stdio.h>

double main()

{

// Local Declarations
double a, b, c;

// Statements
scanf("%lf %lf %lf", &a, &b, &c);

printf("\n\nYour numbers forward: \n%f \n%f \n%f\n\n", a, b, c);
printf("Your numbers reversed: \n%f \n%f \n%f", c, b, a);

return 0;

}```
And I get
1 2 3

1.000000
2.000000
3.000000

3.000000
2.000000
1.000000
Any way I could make the output set the decimal to the hundredths place? o.o

3. Do you mean you want
Code:
```Your numbers reversed:
3.00
2.00
1.00```
?

If so, the way to do that is
Code:
`printf("Your numbers reversed: \n%.2f \n%.2f \n%.2f", c, b, a);`
; the twos are the number of decimal places you want

4. Originally Posted by TheBigH
Do you mean you want
Code:
```Your numbers reversed:
3.00
2.00
1.00```
?

If so, the way to do that is
Code:
`printf("Your numbers reversed: \n%.2f \n%.2f \n%.2f", c, b, a);`
; the twos are the number of decimal places you want
Haha, I was just reading my book and I found out what to do >_>

But thanks for the verification!