鱼C论坛

 找回密码
 立即注册
查看: 2519|回复: 0

[技术交流] 作业 for 【C++语法】《C++快速入门》p2

[复制链接]
发表于 2020-11-9 23:18:20 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x

  1. #include <iostream>
  2. #include<conio.h>
  3. using namespace std;

  4. int max = 1024;
  5. int main()
  6. {
  7.     char flag=0,tempc;
  8.     int i = 0;
  9.     int tempi1=0,tempi2=0;

  10.     while ((tempc = _getch())&& (i < max)) {
  11.         // printf("%c", tempc);
  12.         cout << tempc;
  13.         if ((tempc > '0') && (tempc < '9')) {
  14.             tempi2 = tempi2 * 10 + (tempc - '0');
  15.             flag = 1;
  16.         }
  17.         else {
  18.             if (flag) {
  19.                 tempi1 += tempi2;
  20.                 tempi2 = 0;
  21.                 flag = 0;
  22.             }
  23.             if (tempc == 13)break;
  24.         }
  25.     }
  26.     // printf("\n%d\n",tempi1);
  27.     cout << endl << tempi1 << endl;
  28.     return 0;
  29. }
复制代码

很久没有写过c了,一直在写javascript,c生疏了。
我是从c入门编程的,后来写web前端开发,感觉自己也有点面向对象编程的经验了吧(心虚),于是找到了小甲鱼的c++教程看。这是在p2的结尾的一个作业。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-5-9 20:16

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表