#include<iostream>
using namespace std;
void convertWeight(double ounces, double grams, int pounds, int kilograms);
double output(double ounces, int pounds);
int main()
{
double ounces, grams;
int pounds, kilograms;
char answer;
do
{
cout << "Enter weight in pounds and ounces: " << endl;
cin >> pounds >> ounces;
cout << output(pounds, ounces) << endl;
cout << "Do you want to test again (y/n)?: " << endl;
cin >> answer;
}while (answer == 'y' || answer == 'Y');
return 0;
}
double output(double ounces, int pounds)
{
double grams;
int kilograms;
convertWeight(ounces, grams, pounds, kilograms);
cout << pounds << "pounds and " << ounces << "ounces = " << kilograms << "kilograms and " << grams << " grams." << endl;
return 0;
}
void convertWeight(int pounds, double ounces, int &kilograms, double &grams)
{
double temp = (pounds + ounces/16)/2.2046
kilograms = temp;
grams = (temp - kilograms) * 1000;
}
好吧,我正在尝试编写一个将磅和盎司转换为千克和克的程序。我必须将磅和千克作为 int 类型,将盎司和克作为 double 类型。我觉得这里有一些我没有做过的事情。我正在尝试使用驱动程序并通过按值调用和按引用参数调用的函数。我刚刚编译了我的程序,得到了我见过的最长的错误列表,并且也有我以前从未见过的错误。什么是我没有添加到我应该拥有的程序中?
这是我的以下错误列表:
warning C4244: 'argument' : conversion from 'double' to 'int', possible loss of data
warning C4101: 'kilograms' : unreferenced local variable
warning C4101: 'grams' : unreferenced local variable
error C2146: syntax error : missing ';' before identifier 'kilograms'
warning C4244: '=' : conversion from 'double' to 'int', possible loss of data