最基本的c++代码

这篇文章展示了C++编程中的基本结构,包括函数定义(如`bas()`、`car()`和`numStringKobe()`),用户输入处理,以及条件分支逻辑(如`welcome()`)。主要演示了如何使用`iostream`进行输入输出,并通过`main`函数组织代码执行流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <iostream>
#include <string>
using namespace std;
void james_kobe();
std::string bas() {
    string name;
    cout << "请输入您的目的地" << endl;
    cin >> name;
    cin.get(); // 消耗掉输入的换行符
    return name;
}

std::string car() {
    string carInfo;
    cout << "请输入您的目的地" << endl;
    cin >> carInfo;
    return carInfo;
}

void numStringKobe()
{
    // 使用两层嵌套的for循环打印九九乘法表
    for (int i = 0; i <=9; i++) {
        for (int j = i; j <= i; j++) {
              
            cout << j<< "x" <<i << "=" << (j * i) << endl;
           
         }
        cout << "\t" << endl;
   }

}

void welcome() {
    

    string value;
    cout << "请输入您的交通工具" << endl;
    cin >> value;

    if (value == "公交车") {
        string namebas = bas();

        cout << "一运行公交车函数" << endl;
    }
    else {
        string namecar = car();
        james_kobe();
        
 
        cout << "一运行汽车函数" << endl;
    }
}

int main() {
    welcome();
    numStringKobe();
    cout << "c++运行结果" << endl;
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值