尝试计算分配的夹克、帽子和腰围。输出"0x8049f64"而不是应答
Trying to calculate jacket, hat, and waist size for assignment. Output is "0x8049f64" instead of answer
运行此程序时,我得到了一些奇怪的输出。有什么建议吗?请原谅这个烂摊子。匆匆打字。这是作业的准则。
编写一个程序,询问用户的身高、体重和年龄,以及然后根据公式计算服装尺码:
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)? ";
相关文章:
- 递归函数计算序列中的平方和(并输出过程)
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 请解释"函数1(p1,p2,p3);"的输出
- C++:将控制台输出存储在宏中更好吗
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 为什么我的代码在输出中增加了93天
- 如何从void函数输出字符串
- 输入到文件并输出到另一个文件,并将流文件传递给函数
- AES加密到解密未正确输出
- 如何将c++程序的一些输出传递给shell,以便在shell中使用
- 使用C++程序合并排序没有得到正确的输出
- 为什么我不能在不创建字符串变量的情况下使用函数的字符串输出
- C++格式化输出问题
- 将值从二维数组输出到文本文件
- 集合上的输出迭代器:assign和increment迭代器
- 在while循环中输入带有std::cin的字符串后,控制台会输出大量胡言乱语
- 为什么rk4.do_step不输出C++中的初始条件
- 输出没有重复元素的动态数组(收缩数组)C++
- 尝试计算分配的夹克、帽子和腰围。输出"0x8049f64"而不是应答