新手,写课后题的程序毫无头绪啊QAQ

img


这个是怎么写呢
感觉学了个一周学了个寂寞
知识感觉听懂了,运用不起来
很夸张,很迷茫

这种基础的知识,最好自己先去想怎么做,多看书,都是一些基础语法,自己写的过程中遇到什么错误再发出来请教,不然对你丝毫没有提升,以后找工作怎么办呢

img


代码:

int main(void)
{
    //第一题,输入输出
    while(true)
    {
        cout<<"现在正在下雨嘛?"<<endl;
        char a;
        cin>>a;
        if(a=='Y')
        {
            cout<<"现在正在下雨"<<endl;
            break;
        }    
    }
    //第二题 判断
    cout<<"你考了多少分"<<endl;
    int n;
    cin>>n;

    if(n>=90)
    {
        cout<<"优"<<endl;
    }
    else if(n>=80)
    {
        cout<<"良"<<endl;
    }
    else if(n>=60)
    {
        cout<<"中"<<endl;
    }
    else if(n>=0)
    {
        cout<<"差"<<endl;
    }

    //第三题没拍全。所以暂时没法写
    
}

第一题:

#include<iostream>
using namespace std;

int main()
{
    char ch;
    while (true) {
        cout << "现在还在下雨吗?请输入Y/N" << endl;
        cin >> ch;
        if (ch == 'Y' || ch == 'N') {
            break;
        }
    }
    if (ch=='Y') {
        cout << "现在正在下雨" << endl;
    }
    if (ch == 'N') {
        cout << "现在没有下雨" << endl;
    }
}

效果:

img

第二题提供思路:使用switch case语句或者多重if对你输入的结果进行判断,执行对应结果的代码
第三题思路:写成函数,根据你的输入结果执行不同功能