how can i make a calc that can solve a problem with infinite digits?

I started learning c++ and made a calculator thats very simple but as you can see in the code below, you can only solve problems with 2 numbers and I wanted to know how i could make this program solve a problem with an infinite amount of numbers.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <cstdlib>
#include <iostream>
#include <windows.h>
int ans;
int x;
int y;


using namespace std;

int main(int argc, char *argv[])
{
    cout <<"Welcome to Cheesies calculator." << endl;
    cout <<"For addition press 1." << endl;
    cout <<"For subtraction press 2." << endl;
    cout <<"For multiplcation press 3." << endl;
    cout <<"For division press 4." << endl;
    cin >> ans;
    
    if (ans==1)
    {
               cout <<"You chose to do addition!" << endl;
               cout <<"Please enter the first number." << endl;
               cin >> x;
               cout <<"Now, enter the second number." << endl;
               cin >> y;
               cout <<"calculating......"<< endl;
               Sleep (500);
               cout <<"Finished calculating! Answer:"<< x+y << endl;
                }
    if (ans==2)
    {
               cout <<"You chose to do subtraction!" << endl;
               cout <<"Please enter the first number." << endl;
               cin >> x;
               cout <<"Now, enter the second number." << endl;
               cin >> y;
               cout <<"calculating......"<< endl;
               Sleep (500);
               cout <<"Finished calculating! Answer:"<< x-y << endl;
               }
    if (ans==3)
    {
               cout <<"You chose to do multiplcation!" << endl;
               cout <<"Please enter the first number." << endl;
               cin >> x;
               cout <<"Now, enter the second number." << endl;
               cin >> y;
               cout <<"calculating......"<< endl;
               Sleep (500);
               cout <<"Finished calculating! Answer:"<< x*y << endl;
               }
    if (ans==4)
    {
               cout <<"You chose to do division!" << endl;
               cout <<"Please enter the first number." << endl;
               cin >> x;
               cout <<"Now, enter the second number." << endl;
               cin >> y;
               cout <<"calculating......"<< endl;
               Sleep (500);
               cout <<"Finished calculating! Answer:"<< x/y << endl;
                    }
                    
  

   
    
    system("PAUSE");
    return EXIT_SUCCESS;
}


ty in advance!
Last edited on
If you mean that you give this input: (12+3*(4-2))/5 and it will output 3.6, you should try to read this example: http://www.research.att.com/~bs/dc_command_line.c
A question related to that code:

Sleep(500), 500 is miliseconds?
exactly
sleep(1000) ---> 1 second delay

I remember sleep() was originaly in dos.h, no idea if it's still standard to use this function
Er, Sleep() [notice the capital 'S'] is a <windows.h> function.

The usleep() function is the closest equivalent in POSIX.
http://www.cplusplus.com/forum/unices/10491/page1.html#msg49054

:-)
Topic archived. No new replies allowed.