尝试计算分配的夹克、帽子和腰围。输出"0x8049f64"而不是应答

Trying to calculate jacket, hat, and waist size for assignment. Output is "0x8049f64" instead of answer

本文关键字:输出 0x8049f64 应答 分配 计算 帽子      更新时间:2023-10-16

运行此程序时,我得到了一些奇怪的输出。有什么建议吗?请原谅这个烂摊子。匆匆打字。这是作业的准则。

编写一个程序,询问用户的身高、体重和年龄,以及然后根据公式计算服装尺码:

1.帽子尺寸=磅重除以英寸为单位的高度,全部乘以2.9

2.夹克尺寸(胸围英寸)=身高乘以体重除以288,然后通过每10年增加1/8英寸来调整30岁以上。 (请注意,调整仅在整整 10 年后进行。 因此,30 至 39 岁没有调整,但 40 岁增加了 1/8 英寸。

3.腰围(英寸)=体重除以5.7,然后在28岁以上每2年增加1/10英寸进行调整。 (请注意,仅进行调整整整2年后。 因此,29 岁没有调整,但 30 岁增加了 1/10 英寸。

#include <iostream>
using namespace std;
double hat(double,double);
double jacket(double,double,int);
double waist(double,double,int);
int main ()
{
double height, weight;
int age;
char answer;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
do
{
cout<< "Enter the customer's height in inches: ";
cin>>height;
cout<< "Enter the customer's weight in pounds: ";
cin>>weight;
cout<< "Enter the customer's age: ";
cin>>age;
cout << cout<< "tYour Hat size: " << cout << "tYour Jacket size: "< cout << "tYour Waist size: "<< cout<< "Would you like to continue (y/n)? ";
cin>>answer;
}while(toupper(answer) == 'Y');
return 0;
}
double hat(double weight ,double height)
{
return ((weight/height) * 2.9);
}
double jacket(double height,double weight,int age)
{ 
double size;
int j;
if (age>=30)
{
if((age % 10) !=0)
age = age-(age%10);
j= (age-30)/10;
size =((height * weight) / 288)+((1.0/8)*j);
}
else
size =((height * weight) / 288);
return size;
}
double waist(double height,double weight,int age)
{
double size2;
int k;
if(age >= 28)
{
if((age % 2) !=0)
age = age-(age%2);
k = (age-28)/2;
size2 = (weight/(5.7))+( (1.0/10)*k);
}
else 
size2 = weight / (5.7);
return size2;
}

do 循环中的最后一个 cout <<行是将 cout 到 cout 的管道,而不是您对 cout 的回答。 更不用说在夹克尺寸之后有一个<而不是><<</p>

cout << cout<< "tYour Hat size: " << cout << "tYour Jacket size: "< cout << "tYour Waist size: "<< cout<< "Would you like to continue (y/n)? ";

你甚至从未尝试过计算,所以你没有答案要打印。

相反,我在您的代码中看到了很多cout << cout。 尝试打印cout本身效果不佳。 发生的情况是iostreams不知道如何打印输出流,但是在旧版本的C++中,cout隐式转换为指针,并且流知道如何显示它。 所以你看到的指针等效于 cout .

应在编译器中启用 C++11(或更高版本)支持。 然后cout不会隐式转换为void*,编译器会检测到这样的错误。

你只需要用这行代码替换你的cout

cout<< "tYour Hat size: " << hat(weight ,height) << "tYour Jacket size: "<< jacket( height, weight, age) << "tYour Waist size: "<< waist( height, weight, age)<< "n nWould you like to continue (y/n)? ";