![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Apr 2005
Posts: 19
Rep Power: 0
![]() |
Rate this plz...
Hey Im really new to the whole C thingy and I was wondering if there was anything I should change in my first newbie program :o .
Oh, um when i do the float c = 6.00; and try to printf it, when it outputs it, it shows "6.0000000" whats up wit dat ??? #include<stdio.h>
#include<stdlib.h>
int x;
main() {
int n[5], i=6, f=75;
char name[20], adress[20];
int *prt;
double d = 6.2;
char ch = 'K';
int x = (int) d; // the double variable d is casted into an integer
float c = 6.00;
prt = &n[0];
*prt = 3;
printf("What is your favorite number?");
scanf("%d", &x);
if(x>5)
{
printf("The number you chose is greater than 5!\n");
}
getchar();
printf("\nWhats your Adress?");
fgets(adress,20,stdin);
printf("%s\n", adress);
printf("%d\n", *prt);
printf("Testing output Function\n");
printf("\"Quotes\"\n");
printf("So did this work\?\n");
printf("Here is the Output %d, %f\n", i, c);
printf("%d\n", ch);
printf("%c\n", f);
printf("%d\n", x);
system("pause");
return 0;
} |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
|
It's definately a good start, and it's much less of a workout than looking at beginning C++ programs that are virtually identical, seeing how cout; is truly an eyesore, and iostream is the spawn of Satan.
And for the floats part, it prints out that many decimal places because you use floats for exact values normally, the more exact, the better. So it keeps those reserved. Last edited by Mad_guy; Apr 11th, 2005 at 8:47 PM. |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Apr 2005
Posts: 19
Rep Power: 0
![]() |
So if 6.55 would be an example of a exact value ??
|
|
|
|
|
|
#4 |
|
Hobbyist Programmer
|
You can't get rid of those zero's, unless of course you typecast it to a basic integer, but then you lose your decimal value.
|
|
|
|
|
|
#5 |
|
Expert Programmer
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 555
Rep Power: 5
![]() |
__________________
Johnny was a chemist's son but Johnny is no more, for what Johnny thought was H2O was H2SO4 |
|
|
|
|
|
#6 |
|
Hobbyist Programmer
|
I always forget about the power of format strings.
ALWAYS. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|