在一所小学,午餐期间会提供等量的坚果和干果的混合物。假设每磅坚果中的卡路里数量是每磅干果中卡路里的数量的0.70倍。编写一个程序,提示用户输入小学的学生人数,混合物中每个学生所需的卡路里数量以及每磅坚果中的卡路里数量。该程序输出学生所需的坚果和干果数量。 (为简单起见,假设每个学生需要相同量的卡路里。)
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
int students;
double student_cal, pound_nuts, pound_driedfruits;
cout<<"Enter the number of students in the schools: ";
cin>>students;
cout<<"Enter the calories required for each student: ";
cin>>student_cal;
cout<<"Enter calories in one pound of nuts: ";
cin>>pound_nuts;
pound_driedfruits = pound_nuts/0.70;
}
这应该是输出(SAMPLE RUN):
输入学校的学生人数:365
输入每个学生所需的卡路里:25
在一磅坚果中输入卡路里:14
干果混合物:268.382磅。
坚果混合物:268.382磅。