warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
warning C4244: '+=' : conversion from 'double' to 'int', possible loss of data
warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
warning C4244: '+=' : conversion from 'double' to 'int', possible loss of
Type double can hold decimal places while int cannot (only whole numbers). You're trying to assign double to int. Which means the decimal places are lost.
Anyways, it's a warning not an error. Declare i as type double. Why were you using an int with floating point values (decimals) in the first place?
Those are not 'error'. They are 'warning'. Syntactically ok, but suspicious. In your code they are logically fatal.
The messages should indicate the line, where the issue occurs.
1 2 3
int foo = 42;
foo = 3.14; // first converts 3.14 into an integer (3)and then assigns result to foo
foo += 0.3; // first converts 0.3 into an integer (0) and then adds result to foo
As general guideline, prefer integral loop counters. For example:
1 2 3 4
for ( int bar = 10; bar < 20; ++bar ) {
double gaz = bar * 0.25;
// use gaz
}
Furthermore: your lines 19 and 28-29:
1 2 3
T array[7];
double odd = 0.42;
std::cin >> array[ odd ]; // error: array indices must be integral
@boost lexical cast. Thank you for the response. Because i want to show inside the for loop to print out the following :
2.50m : enter value
3.65m : enter value
and... so on till 4.75m.
@keskiverto Thank you for the response. If i wanted to loop with decimal points ? how is the structure should be done.