所以我是C ++的新手。我正在学习基础知识,并且我一直在尝试编译这个程序。不幸的是,每当我运行它时,瓷砖的价格当然非常低,并且瓷砖的数量也不会以合理的方式返回。请帮忙!
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
double cost_tile, side_tile_in, width_room, lenght_room;
cout << "How much is one tile? \n";
cin >> cost_tile;
cout << "What is the length of one side of a tile in inches? \n";
cin >> side_tile_in;
double side_tile_ft, tile_area_ft;
side_tile_ft = side_tile_in * 12;
tile_area_ft = side_tile_ft * side_tile_ft;
cout << "What is the width of the room in feet? \n";
cin >> width_room;
cout << "What is the length of the room in feet? \n";
cin >> lenght_room;
double area_room, tiles;
area_room = width_room * lenght_room;
tiles = area_room/tile_area_ft;
cout << "You will cover an area of " << area_room << " square feet, with " << tiles << "tiles \n";
cout << "The cost for the tiles will be $" << cost_tile * tiles;
return 0;
}
答案 0 :(得分:2)
要将英寸转换为英尺,除以12,而不是乘以12。