error C2664: 'convert' : cannot convert parameter 4 from 'int' to 'double &‘ 求高手帮忙
//Aprogramthatallowsausertoenteraheightininshesandaweightinpoundsareturnstheheightinc...
// A program that allows a user to enter a height in inshes and a weight in pounds a returns the height in centimeiters ad the weight in kilograms.
#include <iostream>
#include <cmath>
using namespace std;
void explain_program();
// Tells user what program does
void decimal_format (ostream& os);
// Displays decimal numbers in a "nice" format when displayed in os
void read_inches_pounds (int& height_in_inches, int& weight_in_pounds);
// postcondition: height_in_inches and weight_in_pounds have values
// from user at terminal
void convert (int height_in_inches, int weight_in_pounds,
double& height_in_cms, double& weight_in_kilos);
//precondition: height_in_inches and weight_in_pounds are known positive values
//postcondition: height_in_cms and weight_in_kilos have been caculated
void write_out (ostream& os, double height_in_cms, double weight_in_kilos);
//precondition: height_in_cms and weight_in_kilos have values
//postcondition: These values are written to output stream os
const int SENTINEL = -1;
int main()
{
int height_in_inches, weight_in_pounds;
double height_in_cms, weight_in_kilos;
explain_program(); // Tells user what program does
decimal_format(cout); //display decimal numbers in a "nice" format when displayed
read_inches_pounds (height_in_inches, weight_in_pounds);
while ( height_in_inches != SENTINEL)
{
convert( weight_in_kilos, weight_in_pounds, height_in_cms, height_in_inches)
{
height_in_cms = 1/2.54 * height_in_inches;
weight_in_kilos = 1/0.454 * weight_in_pounds;
read_inches_pounds( height_in_inches, weight_in_pounds);
}
}
}
void convert (int height_in_inches, int weight_in_pounds, double& height_in_cms, double& weight_in_kilos)
{
cout<< "Please enter the height in inches (" << SENTINEL << ")===> ";
cin >>height_in_inches;
if (height_in_inches != SENTINEL)
cout << "Please enter the weight in pounds(" <<SENTINEL << ")===> ";
cin >> weight_in_pounds;
}
void write_out (ostream& os, double height_in_cms, double weight_in_kilos)
{
os<< "\n\nThe height in cms is" << height_in_cms;
os << "\n\nThe weight in kilos is" << weight_in_kilos;
}
error C2664: 'convert' : cannot convert parameter 4 from 'int' to 'double &'
error C2143: syntax error : missing ';' before '{'
对不起 我学的不是中文的 看不太懂你说的 能不能帮我改一下 我自己琢磨琢磨 展开
#include <iostream>
#include <cmath>
using namespace std;
void explain_program();
// Tells user what program does
void decimal_format (ostream& os);
// Displays decimal numbers in a "nice" format when displayed in os
void read_inches_pounds (int& height_in_inches, int& weight_in_pounds);
// postcondition: height_in_inches and weight_in_pounds have values
// from user at terminal
void convert (int height_in_inches, int weight_in_pounds,
double& height_in_cms, double& weight_in_kilos);
//precondition: height_in_inches and weight_in_pounds are known positive values
//postcondition: height_in_cms and weight_in_kilos have been caculated
void write_out (ostream& os, double height_in_cms, double weight_in_kilos);
//precondition: height_in_cms and weight_in_kilos have values
//postcondition: These values are written to output stream os
const int SENTINEL = -1;
int main()
{
int height_in_inches, weight_in_pounds;
double height_in_cms, weight_in_kilos;
explain_program(); // Tells user what program does
decimal_format(cout); //display decimal numbers in a "nice" format when displayed
read_inches_pounds (height_in_inches, weight_in_pounds);
while ( height_in_inches != SENTINEL)
{
convert( weight_in_kilos, weight_in_pounds, height_in_cms, height_in_inches)
{
height_in_cms = 1/2.54 * height_in_inches;
weight_in_kilos = 1/0.454 * weight_in_pounds;
read_inches_pounds( height_in_inches, weight_in_pounds);
}
}
}
void convert (int height_in_inches, int weight_in_pounds, double& height_in_cms, double& weight_in_kilos)
{
cout<< "Please enter the height in inches (" << SENTINEL << ")===> ";
cin >>height_in_inches;
if (height_in_inches != SENTINEL)
cout << "Please enter the weight in pounds(" <<SENTINEL << ")===> ";
cin >> weight_in_pounds;
}
void write_out (ostream& os, double height_in_cms, double weight_in_kilos)
{
os<< "\n\nThe height in cms is" << height_in_cms;
os << "\n\nThe weight in kilos is" << weight_in_kilos;
}
error C2664: 'convert' : cannot convert parameter 4 from 'int' to 'double &'
error C2143: syntax error : missing ';' before '{'
对不起 我学的不是中文的 看不太懂你说的 能不能帮我改一下 我自己琢磨琢磨 展开
展开全部
第一个错误是因为函数:
void convert (int height_in_inches, int weight_in_pounds,
double& height_in_cms, double& weight_in_kilos);
第四个参数是接受double&,而你在调用的时候:
convert( weight_in_kilos, weight_in_pounds, height_in_cms, height_in_inches)
使用的参数height_in_inches是int类型。
而且从逻辑上可以看出你这里调用的参数是错误的,正常调用应该是这样的:
convert(height_in_inches,weight_in_pounds, height_in_cms, weight_in_kilos);
----
第二个错误是,你的convert调用是一个函数调用,不是函数声明、定义所以必须得加一个分号在这一句后边:
convert( weight_in_kilos, weight_in_pounds, height_in_cms, height_in_inches) ;
至于后面的大括号其实是没有必要的。
希望能够帮到你,如果还有什么问题,请留言。
void convert (int height_in_inches, int weight_in_pounds,
double& height_in_cms, double& weight_in_kilos);
第四个参数是接受double&,而你在调用的时候:
convert( weight_in_kilos, weight_in_pounds, height_in_cms, height_in_inches)
使用的参数height_in_inches是int类型。
而且从逻辑上可以看出你这里调用的参数是错误的,正常调用应该是这样的:
convert(height_in_inches,weight_in_pounds, height_in_cms, weight_in_kilos);
----
第二个错误是,你的convert调用是一个函数调用,不是函数声明、定义所以必须得加一个分号在这一句后边:
convert( weight_in_kilos, weight_in_pounds, height_in_cms, height_in_inches) ;
至于后面的大括号其实是没有必要的。
希望能够帮到你,如果还有什么问题,请留言。
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询