mercredi 14 février 2018

floating point values not displaying accurate number of digits c++

Having trouble giving the correct digits for my $ output.

every time i plug in for example 8 in the statement i get numbers with 3 digits Ex. 10.9

I just added the setprecision hoping that it will fix the issue, did not work

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


int main()
{
    int Ts;    // holds Ts 
    float Price, Tcost, Total;


    cout << "How many shirts you like ?" << endl;
    cin >> Ts;

    Total = 12 * Ts;

    if ( 5 < Ts && Ts < 10)
        Tcost = (Total - (.10 * Total));
        Price = (Tcost / Ts);
        cout << "he cost per shirt is $" << setprecision(4) << Price << " and the total cost is $" << Tcost << setprecision(4) << endl;




    return 0;


}

Aucun commentaire:

Enregistrer un commentaire