#include <iostream>
using namespace std;
/*Use void functions, they perform some action but do not return a value*/
//Function Protoype, input,read in feet and inches:
void input (double& feet, double& inches);
//Function Prototype, calculate, calculate with given formulae.
void calculate(double& feet, double& inches);
//Function Prototype, output, outputs calculations to screen.
void output (double meters, double centimeters);
int main()
{
double feet;
double inches;
char repeat;
do
{
//Call input:
input(feet, inches);
//Call calculate:
calculate(feet, inches);
//Call output:
output (feet, inches);
cout << "\n";
cout << "Repeat? (Y/N): ";
cin >> repeat;
cout << "\n";
}
while (repeat == 'Y' || repeat == 'y');
}
//Input function definition:
void input (double& feet, double& inches)
{
cout << "Please enter the length in feet" << endl;
cin >> feet;
cout << "Please enter the length in inches" << endl;
cin >> inches;
}
//Calculate function definition, insert formulae here:
void calculate (double& feet, double& inches)
{
feet = (feet * 0.3048);
inches = (inches * 2.54);
}
//Output function definition:
void output (double meters, double centimeters)
{
cout << meters << " meters & " << centimeters << " cm's. " << endl;
}
爲什麼我的轉換不起作用? 或我在做什麼錯?C++轉換不起作用
目標:給定長度以英尺和英寸爲單位,我假設輸出相當於米和釐米的長度。
//Calculate function definition, insert formula here:
void calculate (double& feet, double& inches)
{
feet = (feet * 0.3048);
inches = (inches * 2.54);
}
在SO上發佈問題時,您需要提供儘可能多的相關信息。在這種情況下 - 你如何調用函數? 「不工作」是什麼意思?你得到什麼錯誤信息? – 2010-01-24 12:33:44