这是我的代码:
#include<iostream>
int main() {
int width, length, sq_cm, sq_m{}, sq_in, sq_ft, cm, m, in, ft;
std::cout << "Find the Area and Perimeter of a Rectangle \n\n";
std::cout << "Input the length of the rectangle : \b";
std::cin >> length;
std::cout << "Find the width of the rectangle : \b";
std::cin >> width;
sq_cm = (length * width);
sq_m = (sq_cm / 100);
sq_in = (sq_m * 39.37);
sq_ft = (sq_in / 12);
cm = (length + width);
m = (cm / 100);
in = (m * 39.37);
ft = (in / 12);
std::cout << "Area :" << sq_cm << std::endl;
std::cout << sq_m << std::endl;
std::cout << sq_in << std::endl;
std::cout << sq_ft << std::endl;
std::cout << "Perimeter :" << cm << std::endl;
std::cout << m << std::endl;
std::cout << in << std::endl;
std::cout << ft << std::endl;
return 0;
这是我调试时的样子Find the Area and Perimeter of a Rectangle
Input the length of the rectangle :87
Find the width of the rectangle :68
Area :5916
59
2322
193
Perimeter :155
1
39
3
这就是我想要的样子Find the Area and Perimeter of a Rectangle
Input the length of the rectangle :87
Find the width of the rectangle :68
area:5916 sq cm
59 sq m
2322 sq in
193 sq ft
Perimeter: 155 cm
1 m
39 in
3 ft
最佳答案
要设置文本格式,请尝试以下操作:
使用\ t“制表”输出。
就像Sugar在评论中伤心一样,最好使用"\n"
而不是endl
#include<iostream>
int main() {
int width, length, sq_cm, sq_m{}, sq_in, sq_ft, cm, m, in, ft;
std::cout << "Find the Area and Perimeter of a Rectangle \n\n";
std::cout << "Input the length of the rectangle : \b";
std::cin >> length;
std::cout << "Find the width of the rectangle : \b";
std::cin >> width;
sq_cm = (length * width);
sq_m = (sq_cm / 100);
sq_in = (sq_m * 39.37);
sq_ft = (sq_in / 12);
cm = (length + width);
m = (cm / 100);
in = (m * 39.37);
ft = (in / 12);
std::cout << "\tArea :\n";
std::cout << "\t" << sq_cm << "\n";
std::cout << "\t" << sq_m << "\n";
std::cout << "\t" << sq_in << "\n";
std::cout << "\t" << sq_ft << "\n";
std::cout << "\tPerimeter :\n";
std::cout << "\t" << cm << "\n";
std::cout << "\t" << m << "\n";
std::cout << "\t" << in << "\n";
std::cout << "\t" << ft << "\n";
return 0;
}
它将是这样的:Find the Area and Perimeter of a Rectangle
Input the length of the rectangle :87
Find the width of the rectangle :68
Area:
5916
59
2322
193
Perimeter:
155
1
39
3
关于c++ - C++:如何使我的计算程序的每个答案对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64243264/