Calculator Restriction

Hello

I'm new at C ++ , i'm trying to make calculator using atof() function can someone show me where i can make this restrictions :

make numbers be read as 1,000 instead of 1.

how prevent numbers input such as fractions, fake decimals e.g 1.4.5 , fake commas e.g 1,00 and prevent numbers like this 123abc

how restrict large answer outputs such as 1.2e+999

how to make e and E a number

Thanks for any advice











1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
double a, b;
    char c;
    cin>>a>>c>>b;
    switch (c)
    {
           case '+':
                cout<<a+b;
                break;
           case '-':
                cout<<a-b;
                break;
           case '*':
                cout<<a*b;
                break;
           case '/':
                cout<<a/b;
                break;
           }
This doesn't help me with any restrictions
What you ask for is a lot more complex than vilml has done. The first thing I would learn to do is read them in a strings and start parsing. There are many documents out there on the web on how to do what you ask for. Not to mention you could find odd bits to what you want to find in most compilers. atoi is limiting and I would learn to use stringstream if wanted to convert from strings to actual numbers because it has a lot of great tools for restricting things and/or catching errors in input.
Last edited on
Topic archived. No new replies allowed.