So guys i have a homework to do but its not the case, i have a problem with double
variable
because it is calculated without floating
point like an integer
I've tried writing (double
) before calculation but it didn't work
#include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace std;
int main () {
system ("chcp 1257");
system ("color 8F");
for(int a = 0 ;a <=18;a++){
double t = 8 + (18 - a)/2;
cout << "\n "<<setw(2)<< a << " " << setprecision(1) << fixed << setw(4)<< t ;
};
return 0;
}
The result that i get is this https://i.stack.imgur.com/Lpc2R.png
even though i should get this https://i.stack.imgur.com/reAKa.png
(it's my first post so i can't format images like normal people do)
Edit: The problem was that (double) does not convert all variables in the line of code and variables that are needed for conversion are those that are needed to be divided