Setprecision返回错误

Setprecision返回错误

这是我代码的大部分内容,我需要将最后一个cout设置为具有2的精度,这样我就可以获得小数点后的位置:

#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;


我不知道为什么它不编译?

附注:任何建议将不胜感激。

最佳答案

当C ++编译器抱怨完美的代码时,通常是因为缺少标头。您是否忘记了#include <iomanip>

关于c++ - C++ Setprecision返回错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32743946/

10-11 10:29