Problem with this code


#1

[code]#include <stdio.h>

int main(int argc, const char * argv[])
{

float first;
float second;
first = 3.14;
second = 42.0;

double sum;

sum = first + second;

printf("the sum is: %f . \n");

return 0;

}
[/code]

Not quite sure what is going on because I get this.

the sum is: 128625393781596062540686560876838153772716588044502525912862336525188668742120568047583148652594203302542257156408755557594348398047622084081875158048562357261897654298066957794172370404346123589085815447096515152112084375487434637144640767282642944.000000 .
Program ended with exit code: 0

And it says that there’s “More “%” conversions than data arguments”

Could anyone also explain a bit more about the %f? I kind of get what it does but the book doesn’t really talk much about it.


#2

[quote] printf ("the sum is: %f . \n"); [/quote]
Your printf is missing the required argument.

Remember, for each conversion specifier introduced by the % character, you need to supply an argument.

[Accelerate your learning and become a competent programmer: pretty-function.org]


#3

should be: