Originally Posted by
Salem
> remove the & symbols and have it read
You need the & in these cases.
> but once I start messing with the format specifiers the output goes mental. What am I doing wrong?
Well how many things did you change from 'int' to 'double'?
And how many formats did you change from %d
Note that to scanf a double, you need "%lf", but to print it you only need "%f"
Post an example which doesn't work, if you're still stuck.
Here's my code with the ints changed to doubles and %d changed to %lf (or just %f)
Code:
#include <stdio.h>
void printfunc(double, double);
int main(void)
{
int dub1, dub2;
printf("Enter two decimal integers.\n");
scanf("%lf %lf", &dub1, &dub2);
printfunc(dub1, dub2);
printf("Cheerio for now.\n");
getchar();
getchar();
return 0;
}
void printfunc(double a, double b)
{
printf("%f %f\n", a, b);
}
Adding two float values of 1.2 and 2.2 gives a printed output of 1073846681.000000 and -1717986918.000000