code[
printf("Type in three integers");
scanf("%lf %lf %lf", &m, &n, &o);
printf("%.2f %.2f %.2f", m, n, o);
[/code]
Let's say I put 1 2 -3. How do I make the output look like...
Code:+1.00 +2.00 -3.00
code[
printf("Type in three integers");
scanf("%lf %lf %lf", &m, &n, &o);
printf("%.2f %.2f %.2f", m, n, o);
[/code]
Let's say I put 1 2 -3. How do I make the output look like...
Code:+1.00 +2.00 -3.00
I'm pretty sure you'd have to parse each input manually. Save each input into a string and see if it starts with a '-' or not, then you can output a '+' or '-' as necessary. You'd need to convert each string with atof() too.
Right?
Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.
- Mike McShaffry
Code:printf("%+.2f %+.2f %+.2f", m, n, o);
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
No but if he's taking input like "-3.00" that means your solution is assuming positive values only. Right?
Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.
- Mike McShaffry
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
I thought it might be something about printf() that I didn't know
Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.
- Mike McShaffry
scanf("%lf %lf %lf", &m, &n, &o);
if (m<0) printf("%.2f ",m);
else printf("+%.2f ",m);
if (n<0) printf("%.2f ",n);
else printf("+%.2f ",n);
if (o<0) printf("%.2f ",o);
else printf("+%.2f ",o);
Did you read the other posts? Including Dave's post and link?
This code
automatically adds a '+' or a '-' to the number. You don't need to figure it out yourself.Code:printf("%+.2f", x);
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.