사용자가 프로그램을 계속 사용하려면 다시 묻고 싶은 코드의 마지막 부분 때문에 컴파일 할 코드를 얻을 수 없습니다. 어떤 도움을 주시면 감사하겠습니다. 저는 초보자입니다. # 포함 네임 스페이스 사용 std;while 루프에서 컴파일 오류가 발생했습니다.
//function prototype
void input(double &feet, double &inches);
void conversion(double feet, double &inches, int &meters, double ¢imeters);
void output(int meters, double centimeters);
void main() //Input Function
{
//declaring variables
int meters; //declaring meters
double feet, //declaring feet
inches, //declaring inches
centimeters; //declaring centimeters
//loop
{
input(feet, inches); //function
conversion(feet, inches, meters, centimeters); //function
output(meters, centimeters); //function
}
}
void input(double &feet, double &inches)
{
cout << "Enter number of feet: ";
cin >> feet;
while (feet < 0) {
cout << "ERROR. Please enter a positive value for feet.";
cout << "\nEnter number of feet: ";
cin >> feet;
}
cout << "Enter number of inches: ";
cin >> inches;
while (inches < 0) {
cout << "ERROR. Please enter a positive value for inches.";
cout << "\nEnter number of inches: ";
cin >> inches;
}
}
void conversion(double feet, double &inches, int &meters, double ¢imeters)
{
inches += 12 * feet;
centimeters = inches * 2.54;
meters = centimeters/100;
centimeters -= meters * 100;
}
void output(int meters, double centimeters)
{
char menu;
cout << meters << " meter(s) and " << centimeters << " centimeters " << endl;
cout << "Continue(Y/N) ";
cin >> menu;
} while (menu == 'Y' || menu == 'y');
return 0;
}
거기에'do-while' 루프가 필요합니다. 당신은'do'를 잃어 버렸습니다. – Barmar
나는 또한 그걸 시도했으나 아마 잘못했다. do-while 루프 반환 값이 함수 유형과 일치하지 않고 또한 'output' 'void'함수에서 값을 반환하는 2 개의 오류가 발생한다. do-while 루프 void 출력 (int 미터, 2 센티미터) { \t char menu; \t \t cout << meters << "meter (s) and"<< 센티미터 << "센티미터"<< endl; \t \t do { \t \tcout << "Continue (Y/N) :"; \t \t cin >> menu; \t} while (menu == 'Y'|| menu == 'y'); \t return 0; } – jackblack
'void' 함수에는'return 0;'이 없어야합니다. – Barmar