I made this code as an example of my question. The actual program I will be making is bigger but I made this just to test, and be able to show what I'm asking.
The result is:
3.5
3
If average2 is a float and is being set equal to (7/2) why isn't it 3.5 instead of 3? I know for int values it drops off the remainder or decimal but if average2 is a float why won't it keep the decimal? It's probably something really easy or stupid I've forgotten.
Thanks.
Code:
#include <iostream> using namespace std; int main() { float average; float average2; average=3.5; average2=(7/2); cout << average << endl; cout << average2 << endl; return 0; }
3.5
3
If average2 is a float and is being set equal to (7/2) why isn't it 3.5 instead of 3? I know for int values it drops off the remainder or decimal but if average2 is a float why won't it keep the decimal? It's probably something really easy or stupid I've forgotten.
Thanks.
Comment