How do I make my number show as 1.0 instead of 1

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
float membership = 2500.00;


cout<<"Membership fee \tYear\n"
<<"-------------------------------------\n";
for( int year = 2; year <= 6; ++year)
{
membership += (membership * 0.04);
cout<<setprecision(6);
cout<<membership<<" \t\t\t "<<year<<endl;
}

return 0;
}

it all works i just dont like that the first two dont have decimals
You will probably also want to use std::ios::fixed() and std::iso::showpoint() as well.
1
2
float decnum = 25.75;
cout << std::fixed << std::setprecision(2) << decnum << endl;


will output: 25.75
closed account (EwCjE3v7)
When floatfield is set to fixed, floating-point values are written using fixed-point notation: the value is represented with exactly as many digits in the decimal part as specified by the precision field (precision) and with no exponent part.


http://www.cplusplus.com/reference/ios/fixed/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iomanip>

int main()
{
    float membership = 2500.00;

    std::cout <<"Membership fee \t\t\tYear\n"
              << "-------------------------------------\n";

    for( int year = 2; year <= 6; ++year)
    {
        membership += (membership * 0.04);
        std::cout << std::fixed << std::setprecision(2);
        std::cout << membership << " \t\t\t " << year << std::endl;
    }

    return 0;
}
Topic archived. No new replies allowed.