C++入门经典第一章编程练习

1.

#include "pch.h"
#include 
using namespace std;

int main()
{
    int numberOfPods, peasPerPod, totalPeas;
    cout << "请输入豆荚的数量:\n";
    cin >> numberOfPods;
    cout << "请输入每个豆荚里豆子的数量:\n";
    cin >> peasPerPod;
    totalPeas = numberOfPods * peasPerPod;
    cout << "您的总豆子数量为:\n" << totalPeas;
}

2.

#include "pch.h"
#include 
using namespace std;

int main()
{
    cout << "Hello\n";
    int numberOfPods, peasPerPod, totalPeas;
    cout << "请输入豆荚的数量:\n";
    cin >> numberOfPods;
    cout << "请输入每个豆荚里豆子的数量:\n";
    cin >> peasPerPod;
    totalPeas = numberOfPods * peasPerPod;
    cout << "您的总豆子数量为:\n" << totalPeas << "\n";
    cout << "Good-bye\n";
}

5.

#include "pch.h"
#include 
using namespace std;

int main()
{
    cout << "Hello\n";
    int numberOfPods, peasPerPod, totalPeas;
    int w, h, t;
    cout << "请输入豆荚的数量:\n";
    cin >> numberOfPods;
    cout << "请输入每个豆荚里豆子的数量:\n";
    cin >> peasPerPod;
    totalPeas = numberOfPods*peasPerPod;
    cout << "您的总豆子数量为:\n" << totalPeas << "\n";
    cout << "请输入篱笆长度:\n";
    cin >> w;
    cout << "请输入篱笆宽度:\n";
    cin >> h; 
    cout << "请输入篱笆总长度:\n";
    cout << w + w + h + h<<"\n";
    cout << "Good-bye\n";
}

你可能感兴趣的:(C++入门经典学习)