I am assuming that this is a very stupid question but I am learning this stuff and anyways I was just playing around trying to make a program that uses constants, it only adds like 2 numbers to the users number but anyways when I compile it I get this warning:
warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
Now I don't know how to fix it though I have an idea of what the problem is, like you can't have data in one type of a variable/constant and then move it to another type but as of yet.
There is one other thing, this error only appears sometimes, I will open it, compile it will say the compiler needs to create these files(blah blah blah) then it will be fine, I then took out a "\n" to make in neater and it gave me the warning but then I executed it and it screwed up as usual but when I recompiled the warning was gone so I don't get it.
I don't know how to fix it, can someone help please?
Code:
#include <stdio.h>
/*This program is designed to test how literal constants and other types of constants work.*/
#define DECIMAL .2354698
const int whole = 10;
int userVariable;
int userTotal;
void userNumber(void)
{
printf("This program will take whatever number you enter and add .234698 to it, and then");
printf("add 10 to it as well, it is a test to see how constants work\n\n");
printf("Please enter your number and the program will add to it: ");
scanf("%i", &userVariable);
userTotal = DECIMAL + whole + userVariable;
}
main(void)
{
userNumber();
printf("\nThe result of adding %f and %i to %f is: %f\n", DECIMAL, whole, userVariable, userTotal);
return 0;
}
Thanks a lot