# At My Wit's End (concerns passing char to constructor)

• 03-25-2004
MisterWonderful
At My Wit's End (concerns passing char to constructor)
PURPOSE OF PROG: user enters an arithmetic problem with two terms. Based upon the rules of significant digits, the program calculates the answer, and returns what the answer should be, adjusting for sig digs.

(This next part makes more sense having read the code)

PROBLEM: I input, e.g.: 24.6 + 78.
The program takes ea. member of the first array of numbers, call the Digit constructor, and passes val to the constructor, which should declare the passed value to be itsVal.
After getting screwy feedback, I tried putting a cout<< in the constructor call so that it would output what it considered val to be. It output: 50 52 54 , or something similar to that. Sure enough, this corresponds to "2","4", and "6" on the ASCII chart.

I'm aware that there are probably many more errors to be found in my newbie-esque code.

Many thanks to any and all who shed even the faintest light on my little problem.

Code:

``` #include <iostream> enum {ZERO, NONZERO, DECIMAL}; enum {DEC_DECLARED}; enum {TRUE, FALSE}; class Digit {  public:         Digit(char val);   ~Digit(void) { }     void Show(void) const {std::cout<< itsValue << std::endl;}     int get_isItZero() const {return isItZero;}         int get_itsValue() const {return itsValue;}  private:         int itsValue;         int isItZero; }; Digit::Digit(char value) {                                         if(value != '.')  {   itsValue = value; // how on earth do I cast this correctly?   std::cout<< ""<< itsValue <<" ";  }  else   itsValue = DECIMAL;  if(itsValue==0)  {   isItZero = ZERO;  }  else   isItZero = NONZERO; }  // I excised all of the linked list stuff.  I determined that the issue  // was arising before it was even inserted into the LL. int main(void) {  char numA[50];  char numB[50];  char oper;  std::cin>> numA >> oper >> numB;  Digit * p_Digit;  LinkedList ll;  for(short iA=0; iA<50; iA++)  {   // regarding this clumsy switch(case) -   // any suggestions as to making this less klunky?   switch(numA[iA])   {   case '0':           p_Digit = new Digit(numA[iA]);           ll.Insert(p_Digit);           break;   case '1':           p_Digit = new Digit(numA[iA]);           ll.Insert(p_Digit);           break;   case '2':           p_Digit = new Digit(numA[iA]);           ll.Insert(p_Digit);           break;   case '3':       p_Digit = new Digit(numA[iA]);           ll.Insert(p_Digit);           break;   case '4':       p_Digit = new Digit(numA[iA]);           ll.Insert(p_Digit);           break;   case '5':       p_Digit = new Digit(numA[iA]);           ll.Insert(p_Digit);           break;   case '6':       p_Digit = new Digit(numA[iA]);           ll.Insert(p_Digit);           break;   case '7':       p_Digit = new Digit(numA[iA]);           ll.Insert(p_Digit);           break;   case '8':       p_Digit = new Digit(numA[iA]);           ll.Insert(p_Digit);           break;   case '9':       p_Digit = new Digit(numA[iA]);           ll.Insert(p_Digit);       break;   case '.':       p_Digit = new Digit(numA[iA]);           ll.Insert(p_Digit);           break;   default:           break;                            }  }  return 0; }```
• 03-26-2004
WaltP
value is the character '2' or 50. You want 2. So try:
Code:

```itsValue = value - 48;  // or itsValue = value - '0';```