Search code examples
c++compilationdecimalpoints

C++ Setprecision returning an error


This is the majority of my code and I need to set the last cout to have precision of 2, so I can get places after the decimal point:

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

/*
 * 
 */
int main(int argc, char** argv) {
    int length_room, width_room ;
    int length_tile, width_tile ;
    int room_ft;
    int tile_ft;
    int tiles_needed;
    double cost;
    double cost_room;


    cout <<"Enter the length of the room (in feet) ";
    cin >> length_room ; 
    cout << "Enter the width of the room (in feet) " ;
    cin >> width_room ; 
    cout << "Enter the length of the tile (in inches) " ;
    cin >> length_tile ;
    cout << "Enter the width of the tile (in inches) ";
    cin >> width_tile ;
    cout << "Enter the amount for each tile " ;
    cin >> cost;

        length_tile=(length_tile/12);
        width_tile=(width_tile/12);
        tile_ft=(length_tile*width_tile);
        room_ft=(length_room*width_room);
        tiles_needed=(room_ft/tile_ft);
        cost_room=(cost*tiles_needed);
    cout<<endl;
    cout<<endl;

    cout << "Length of the room " <<length_room<<" ft"<<endl;
    cout << "Width of the room "<<width_room<<" ft"<<endl;
    cout << "Least number of tiles needed "<<tiles_needed<< " tiles"<<endl; /* Need to round up still */

    cout << fixed <<setprecision(2)
            <<"Total Cost: $" << cost_room <<endl; /* Need to mod still to 2 decimal places */



    return 0;

I cannot figure out why it is not compiling ?

P.S.:Any suggestions would be greatly appreciated.


Solution

  • When C++ compiler complains about perfectly fine code, it is often because missing headers. Didn't you forget #include <iomanip>?