Hey guys, I've got a really simple question, but i really can't solve this stupid thing.
I usually use cin & cout for input and output, but I also wanted to learn to use the old fashioned printf and scanf
I created a very basic program with 'double' variables, and I tried to use "%f" for printf and scanf, unfortunately the compiler told me that "%f" is only for float variables... I also tried to use "%2f" instead ( because of the variable dimension), but it didn't work...
1 2 3 4 5 6 7 8
{ double a, b, sum;
printf("Please insert a value for variable a:\n");
scanf("%f", &a);
printf("Please insert a value for variable b:\n");
scanf("%f", &b);
sum= a+b;
printf("The sum of %f and %f is: %f\n", a, b, sum);
return 0; }
If you really want to use these C functions in your C++ program I suggest you use your favourite search engine and find and study the documentation for these functions. These C functions have different format specifiers for every type of variable and you will need to use the correct specifier. The documentation is the place to get this type of information.
By the way I don't recommend using these C stdio functions in a C++ program, stick with the C++ streams. The C++ streams are much less error prone and can be overloaded to print your user defined types.