0
저는 프로그래밍에 익숙하지 않으며 대학 공학 프로그램. 나는 재미있게 수업을하기로 결정했습니다. 저는 사용자가 직각 프리즘의 길이, 너비 및 높이에 대해 3 가지 값을 입력 할 수있게 해주는 프로그램을 C++로 작성하려고합니다. 프로그램은 3 개의 값을 사용하여 프리즘의 표면적과 부피를 계산합니다.오류 : '연산자 *'에 일치하는 항목이 없습니다 (피연산자 유형이 'std : : string {일명 basic_string <char>}'이고 {aka std basic_string <char>} ')
이것은 내가 지금까지 가지고있는 것입니다. (보카 름)
//---------------------------------------------------------------------------------------//
//Calculate rectangular prism//
//---------------------------------------------------------------------------------------//
#include <string>
#include <iostream>
using namespace std;
int main()
{
string length; // length of prism in cm
string width; // width of prism in cm
string height; // height of prism in cm
cout << "Please enter the length, width, and height of the rectangular prism." << endl;
cin >> length; //length of prism in cm
cin >> width; //width of prism in cm
cin >> height; //height of prism in cm
double volume; //volume of prism in cm^3
double sa; //surface area of prism in cm^2
volume = length * width * height;
sa = (length * width * 2) + (width * height * 2) + (height * length * 2);
cout << "The volume of the rectangular prism is " << volume << " cm^3." << endl;
cout << "The surface area of the rectangular prism is " << sa << " cm^2." << endl;
return 0;
}
//Whenever I try to compile, I'll get 4 error messages that reads
//"error: no match for 'operator*' (operand types are 'std: :string {aka std basic_string<char>}' and {aka std basic_string<char>}')
//ps these 3 comments aren't in the code
어떻게 수정해야합니까?
float
또는double
(또는int
)에 자신의 유형을 변경 컴파일하려면 * width * height;'- 변수를 초기화하고, 할당하지 않고, 가능한 경우 const로 선언하는 것을 선호한다. –