我如何编写程序,识别数字(0-9) [英] How I can write a program, what recognize numbers (0-9)

查看:112
本文介绍了我如何编写程序,识别数字(0-9)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到一个任务,制作一个程序,什么是识别数字,但我不知道如何启动它。我能用C ++做这个吗?抱歉我的英语不好,我来自匈牙利,我不会说英语非常好,但我理解大部分的事情



我尝试过的事情:



我什么都不做,因为我在编程中初学者

Hi,i get an task,to make a program,what is recognize numbers,but i dont know how to start it.Can i make this in C++?Sorry for my bad english,i'm from Hungary,and i dont speak english very good, but i understand most of the things

What I have tried:

I don't try nothing,because im beginner in the programming

推荐答案

(如果我找到你的话)只需迭代输入字符和首先停在非数字位置,例如

(if I got you) Just iterate on the input characters and stop at first non-digit one, e.g.
#include <iostream>
#include <string>
using namespace std;

int main()
{
  string line;
  getline(cin, line);
  for (auto c : line)
    if ( c < '0' || c > '9')
    {
      cout << "invalid number " << endl;
      return -1;
    }

  cout << "valid number " << endl;
}


这篇关于我如何编写程序,识别数字(0-9)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆