Trying to understand my warnings on 'double' to 'const int' possible loss of data and truncation from 'double' to 'float'.
Not sure where I went wrong.........Need help understanding.
Warning 1 warning C4244: 'initializing' : conversion from 'double' to 'const int', possible loss of data
Warning 2 warning C4305: 'initializing' : truncation from 'double' to 'float'
This is what I have for my variables:
//input variables
float SLICES = 0.0;
int const PI = 3.14;
float SLICE_AREA = 14.13;
float radius;
Please help me understand where I went wrong. I am a beginner.
Truncation is when the fractional part of a floating-point literal/value is removed so it's compatible with a integral type.
Edit:
Here's what's happening: The int type can only hold whole numbers. The float/double types can hold whole & fractional numbers (numbers such as 4.3). When a floating point number (a number with a fractional counterpart) is assigned to a variable of type int, the compiler will notice and truncate the fractional counterpart. Here's an example:
1 2 3 4
int Integer(0);
float Real(1.2F); // The 'F' denotes the literal as a 4-byte float.
Integer = Real; // Truncation here.
In the above code, when Integer is assigned to Real, the .2 of Real's value is removed (truncation). The resulting value is compatible with int.
guys need help in running this code.dont know why it is getting struck??
//program to insert data in a sorted file.....
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
class stu
{ int rollno;
char name[20];
int Class;
float marks;
char grade;