저는 C++에 조금 익숙합니다. 영화 티켓의 총 합계를 계산하기 위해이 작은 프로그램을 만들고 있습니다.왜 나는 제로를 얻고 있습니까?
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
using namespace std;
int adultTick, childTick;
const int aPrice = 14;
const int cPrice = 10;
float rate() {
const double RATE = .20;
return RATE;
}
double grossTotal = (aPrice * adultTick) + (cPrice * childTick);
int main() {
cout << "Box Office Earnings Calculator ....\n" << endl;
cout << "Please Enter the Name of the Movie: ";
string movie_name;
getline(cin, movie_name);
cout << endl << " \" \" " << "adult tickets sold: ";
cin >> adultTick;
cout << " \" \" " << "child tickets sold: ";
cin >> childTick;
cout << endl << setw(10) << left << "Movie Title: " << setw(20) << right << " \" " << movie_name << " \" " << endl;
cout << setw(10) << left << "Adult Tickets Sold: " << setw(20) << right << adultTick << endl;
cout << setw(10) << left << "Child Tickets Sold: " << setw(20) << right << childTick << endl;
cout << setw(10) << left << "Gross Box Office Profit: " << setw(20) << right << "$ " << grossTotal;
}
마지막으로 프로그램의 총계를 표시하는 위치는 무엇입니까? 나는 산술이 정확하다고 생각했지만 이해하지 못합니다. 왜 계속해서 0을 표시합니까? 나는 무엇을 잘못 할 수 있 었는가? 산술 "grossTotal"에 대한 변수를 만들지 않으면 작동하지만 "setprecision"및 "fixed"함수로 추가 서식을 지정해야합니다.
잘 모르겠지만, 주된 점은 선언이 관계를 지정하지 않는다는 것입니다. 단지 초기 값만을 지정합니다. –