问题描述
每次我运行这段代码时,只有第一个 cout 和 cin 语句允许用户输入。它不会跟进其他代码行。只需打印到终端
#include<iostream>
using namespace std;
int main(){
int adultTickets,childTickets,grossprofit,netProfit,distributor,adultSold,childSold;
char movieName,movieTitle;
cout << "Please enter the name of the movie: ";
cin >> movieName;
cout << "\nHow many ADULT tickets sold: ";
cin >> adultSold;
cout << "\nHow many CHILD tickets sold: ";
cin >> childSold;
adultTickets = 6 * adultSold;
childTickets = 3 * childSold;
grossprofit = adultTickets + childTickets;
netProfit = (grossprofit * 20) / 100;
distributor = grossprofit - netProfit;
cout << "\nAdult Tickets Sold: " << adultSold << endl;
cout << "Child Tickets Sold: " << childSold << endl;
cout << "Gross Box Office Profit: " << grossprofit << endl;
cout << "Amount paid to distributor: " << distributor << endl;
cout << "Net Box Ofiice Profit: " << netProfit << endl;
}
解决方法
看起来我只是通过将字符串大小声明给我的 movieName[25]
变量来解决这个问题的。