Inputed String to Int Variable Help

Hello,

I am working on this program to store 5 strings and turn them into variables, And then running them through the MAD (Mean, Absolute, Deviation) equations. And by "User Inputed String", I mean a number so its, Input -> String -> Int -> Equation.

Any help is a appreciated,
~Jim
So, by string you mean, for instance "five" or "5"? In the first case, you need a lookup table that translates the string "five" to the int 5. In the latter case, you can use the function atoi(). The breakdown of the program is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
using namespace std;

int main()
{
     cout << "Enter strings: ";
     string astr[5];
     int i = 0;
     while (i < 5) cin >> astr[i++];
     int a[5];
     // lookup or convert the elements of astr to a
     // apply equations
    return 0;
}
Last edited on
Thanks, Right now the User inputs five numbers and then a While Loop, That then converts them to a Int. Now I just need to run them through MAD.
Topic archived. No new replies allowed.