Why doesn't my array read in correctly?

I'm working on a program that reads in characters and then has to convert them to integers in order to finally multiply them all. When I go through my code in the debugger I see that the program is not assigning the integer to the array. How am I doing it wrong? I tried doing it by just assigning it like this first:

firstLineAry[a] = (ch - '0');


but it didn't like that. That seemed to set ch to zero. So I tried again, but still won't set my number to firstLineAry[a]. Why is that? Why doesn't Line 4 do what I want it to do?


1
2
3
4
5
6
7
8
9
10
while (ch != '\n')       //While character is not a new line character
        {
            x = (ch - '0');      //Convert char to int
            firstLineAry[a] = x; //Put the first converted number into the rightmost pos within first num array
            cout << setw(50) << firstLineAry[a];     //Display rightmost number
            outfile << setw(50) << firstLineAry[a];  //Echo
            lengthA ++;         //Determine how long each array is
            a--;                //Decrement array position counter
            infile.get(ch);     //Get next character
        }
Last edited on
Topic archived. No new replies allowed.