花花生病了,妈妈去给花花买儿童止咳糖浆。一瓶儿童止咳糖浆的规格及用法如下所示,一般花花咳嗽需要5天才能痊愈。 止咳糖浆规格:每瓶120毫升,每日3次,10岁以上儿童:每次25毫升,7~10岁儿童:每次15毫升,3~6岁儿童:每次5毫升。 请根据止咳糖浆的规格以及花花的年龄计算,写一个程序计算如果花花要痊愈,妈妈至少要买几瓶止咳糖浆?(4.1.7)
这题我认为只要用分支就行
代码见下(不喜勿喷):
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int age;
cin>>age;
int total,cnt;
if (age > 10)
{
total = 25*3*5;
}
else if(age >= 7 && age<=10)
{
total = 15*5*3;
}
else
{
total = 5*5*3;
}
if (total %120 == 0)
{
cout<<total/120 <<endl;
}
else
{
cout<<total/120+1<<endl;
}
}