首页 新闻 搜索 专区 学院

C++新手问题

0
悬赏园豆:20 [已解决问题] 解决于 2020-12-01 00:48

A city offers the following prices for monthly bus passes:
· Age 0 – 5: $0
· Age 6 – 17: $80
· Age 18+ and less than $15,000 income: $30
· Age 65+ and less than $30,000 income: $70
· City employee: $50
· General population: $100
Write a program that finds the best bus price for a given user.

c++
心律的主页 心律 | 初学一级 | 园豆:136
提问于:2020-11-30 23:02
< >
分享
最佳答案
0
#include <iostream>
using namespace std;

int main()
{
    char c;
    int age,income;
    cout<<"Please input your age: ";
    cin>>age;
    cout<<"Please input your income: ";
    cin>>income;
    cout<<"Are you a City employee? (input Y or N) : ";
    cin>>c;

    // 输出用户的信息,以便用户自查
    cout<<"Age = "<<age<<endl;
    cout<<"Imcome = "<<income<<endl;
    if(c=='Y')  cout<<"You are a City employee."<<endl;
    else if(c=='N') cout<<"You are a General population."<<endl;

    // 判断最低价格
    if(age>=0 && age<=5)
    {
        cout<<"The best bus price for you is $0."<<endl;
    }
    else if(age>=18 && income<15000)
    {
        cout<<"The best bus price for you is $30."<<endl;
    }
    else if(c=='Y')
    {
        cout<<"The best bus price for you is $50."<<endl;
    }
    else if(age>=65 && income<30000)
    {
        cout<<"The best bus price for you is $70."<<endl;
    }
    else if(age>=6 && age<=17)
    {
        cout<<"The best bus price for you is $80."<<endl;
    }
    else
    {
        cout<<"The best bus price for you is $100."<<endl;
    }
}
展开代码内容
收获园豆:20
Conan-jine | 小虾三级 |园豆:1272 | 2020-12-01 00:27
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册