1. ## couple questions...

how do i write a value of a float to standard output?

I thought it'd be the same as putting an int which would be

Code:
`printf ( "%d\n", fraction );`
but apparently not =/

and is it written the same way for double?

also this question.....

Write a complete program that
declares an integer variable,
reads a value from the keyboard into that variable, and
writes to standard output the square of the variable's value.

this is waht i wrote

Code:
```#include <stdio.h>
int main ()
{
int x ; {
scanf ( "%d\n", &x);
x = x* x;
printf ( "%d\n", x);
}
getchar ();
}```
that part, the TA added it for me but the thing is, he doesnt speak english, so he couldnt explain what that is...

is that how you get square of something? (looks like x = x times x which would square it)

and there is this question...

writes to standard output the variable's value, twice the value, and the square of the value, separated by spaces.

the square is x = x* x but how would i times it by two?

i wrote

Code:
```x = x*x;
x = x* 2;```
but apparently its wrong.... and what does it mean separated by space ? put everything in 1 line?

2. how do i write a value of a float to standard output?
With the %f format specifier:
Code:
`printf("%f\n", fraction);`
and is it written the same way for double?
Yes, but only with printf. You have to be careful to use %f for float and %lf for double when using scanf. There's a big difference because printf can promote a float to double while scanf cannot promote a pointer to float to a pointer to double.
is that how you get square of something? (looks like x = x times x which would square it)
Yea, that's certainly the easiest way.
the square is x = x* x but how would i times it by two?
x = x * 2, or the shorthand x *= 2.
and what does it mean separated by space ?
Whitespace doesn't mean anything in C, except where it does, so you can usually add whitespace wherever you want to make code easier to read. Your TA didn't do a good job of that, though.

3. Question #1 - Check out http://www.die.net/doc/linux/man/man3/printf.3.html. Look under "The conversion specifier". float and double are the same thing to printf().

Question #2 - You're going to have to do the calculations within the printf() call instead of in a seperate statement since you need to print the values seperated by a space (yes, on the same line).

4. i'm curious why this isnt working then...

question
Write a complete program that
declares an integer variable,
reads a value from the keyboard into that variable, and
writes to standard output the variable's value, twice the value, and the square of the value, separated by spaces.

Code:
```#include <stdio.h>
int main ()
{
int x ; {
scanf ( "%d\n", &x);
x = x * 2;  x= x * x;
printf ( "%d\n", x);
}
getchar ();
}```

5. Code:
`x = x * 2  x= x * x;`
You need to separate these two operations with a semicolon or a comma:
Code:
`x = x * 2;  x= x * x;`
But if you need to output both the the value multiplied by 2 and the value squared, you need to do the operation and print it separately, otherwise changes made in the first operation will affect the second:
Code:
```#include <stdio.h>

int main() {
int x;

scanf("%d", &x);
printf("%d %d\n", x * 2, x * x);

return 0;
}```

6. Originally Posted by Narf
Code:
`x = x * 2  x= x * x;`
You need to separate these two operations with a semicolon or a comma:
Code:
`x = x * 2;  x= x * x;`
But if you need to output both the the value multiplied by 2 and the value squared, you need to do the operation and print it separately, otherwise changes made in the first operation will affect the second:
Code:
```#include <stdio.h>

int main() {
int x;

scanf("%d", &x);
printf("%d %d\n", x * 2, x * x);

return 0;
}```
yeah i made a typo with that, i added it in though heh...

that code didnt work either. Keeps saying
Suggestion: You didn't write out the number read in.

7. that code didnt work either.
You're confusing "doesn't work" with "doesn't do exactly what you want". It works fine given correct input, and you should have no trouble modifying it to print x first.

8. Originally Posted by Narf
You're confusing "doesn't work" with "doesn't do exactly what you want". It works fine given correct input, and you should have no trouble modifying it to print x first.
you're right sorry...

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

int main() {
int x;

scanf("%d", &x);
printf("%d %d", x * 2, x * x);

return 0;
}```
its doing what it exactly wants it to do now but its still saying its not correct.....

i give up, imma have to ask the teacher tommorow, at least she speaks english lol

9. declares an integer variable,
Code:
`int x;`
reads a value from the keyboard into that variable, and
Code:
`scanf("%d", &x);`
writes to standard output the variable's value, twice the value, and the square of the value, separated by spaces.
Code:
`printf("%d %d %d\n", x, x * 2, x * x);`
Q.E.D