error C2679 !!

biohazard357
biohazard357 used Ask the Experts™
on
Please don't laugh at me for my programming being weak, i'm in the first year of my CompSci course and i've never done it before.

i have defined:

void printInt(int number); //outside main

count is an unsigned counter

printInt(count) is reading error C2679 and i do not know why. I saw the other topic on this error message but it was WAY over my head.

Thanking you in a advance.

C Laughton
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Can you paste your whole code here and ill try and fix it?

Author

Commented:
# include <iostream>
# include <string>
using namespace std;

unsigned count2;
int convertNumber (string pNumber);
bool isNumberString (string pNumber);
void printInt (int number);

int main()
{
      int a;
      
      int b;
      char lOOp;
      string alpha;
      string bravo;
      string MATHoP;
      string equals;
      char mathOp;
      unsigned count;
      unsigned count2;

      count = 0;
      count2 = 0;
      
      do
      {
            cout << "Enter calculation: ";
            cin >> alpha;
            isNumberString(alpha);
            a = convertNumber(alpha);
            cin >> MATHoP;
            cin >> bravo;
            isNumberString(bravo);
            b = convertNumber(bravo);
            cin >> equals;
            
            {

                  if (MATHoP == "plus" || MATHoP == "PLUS")
                  {
                        mathOp = '+';
                  }
                  else if (MATHoP == "minus" || MATHoP == "MINUS")
                  {
                        mathOp = '-';
                  }
                  else if (MATHoP == "times" || MATHoP == "TIMES")
                  {
                        mathOp = '*';
                  }
                  else if (MATHoP == "over" || MATHoP == "OVER")
                  {
                        mathOp = '/';
                  }
                  else
                  {
                        cout << "*** ERROR: the operator string: " << MATHoP << " :is not recognised ***" << endl;
                  }

            if (equals != "equals")
            {
            cout << "*** ERROR: expected the string ""equals"" and found: " << equals << " :***" << endl;                  
            }
            
            cout << a << " " << mathOp << " " << b << " =" << endl;
            
            if (mathOp == '+')
            {
                  cout << "Answer: " << a+b << endl;
                  count = count++;
            }

            else if (mathOp == '-')
            {
                  cout << "Answer: " << a-b << endl;
                  count = count++;
            }

            else if (mathOp == '*')
            {
                  cout << "Answer: " << a*b << endl;
                  count = count++;
            }

            else if (mathOp == '/')
            {
                  cout << "Answer: " << a/b << endl;
                  count = count++;
            }
      }
      
            cout << "Do you wish to perform another calculation?: ";
            cin >> lOOp;

      }      while (lOOp != 'N' && lOOp != 'n');

      cout << printInt(count) << " successful calculations and " << printInt(count2) << " unsuccessful" << endl;
      cout << endl;
      
      return 0;
}

int convertNumber(string pNumber)
{
      if (pNumber == "one")
      {
            return  1;
      }
      else if (pNumber == "two")
      {
            return  2;
      }
      else if (pNumber == "three")
      {
            return  3;
      }
      else if (pNumber == "four")
      {
            return  4;
      }
      else if (pNumber == "five")
      {
            return  5;
      }
      else if (pNumber == "six")
      {
            return  6;
      }
      else if (pNumber == "seven")
      {
            return  7;
      }
      else if (pNumber == "eight")
      {
            return  8;
      }
      else if (pNumber == "nine")
      {
            return  9;
      }
      else if (pNumber == "ten")
      {
            return  10;
      }
      else if (pNumber == "eleven")
      {
            return  11;
      }
      else if (pNumber == "twelve")
      {
            return  12;
      }
      else if (pNumber == "thirteen")
      {
            return  13;
      }
      else if (pNumber == "fourteen")
      {
            return  14;
      }
      else if (pNumber == "fifteen")
      {
            return  15;
      }
      else if (pNumber == "sixteen")
      {
            return  16;
      }
      else if (pNumber == "seventeen")
      {
            return  17;
      }
      else if (pNumber == "eighteen")
      {
            return  18;
      }
      else if (pNumber == "nineteen")
      {
            return  19;
      }
      else if (pNumber == "twenty")
      {
            return  20;
      }
      return 0;
}

bool isNumberString(string pNumber)
{
      if (pNumber == "one")
      {
            return true;
      }
      else if (pNumber == "two")
      {
            return true;
      }
      else if (pNumber == "three")
      {
            return true;
      }
      else if (pNumber == "four")
      {
            return true;
      }
      else if (pNumber == "five")
      {
            return true;
      }
      else if (pNumber == "six")
      {
            return true;
      }
      else if (pNumber == "seven")
      {
            return true;
      }
      else if (pNumber == "eight")
      {
            return true;
      }
      else if (pNumber == "nine")
      {
            return true;
      }
      else if (pNumber == "ten")
      {
            return true;
      }
      else if (pNumber == "eleven")
      {
            return true;
      }
      else if (pNumber == "twelve")
      {
            return true;
      }
      else if (pNumber == "thirteen")
      {
            return true;
      }
      else if (pNumber == "fourteen")
      {
            return true;
      }
      else if (pNumber == "fifteen")
      {
            return true;
      }
      else if (pNumber == "sixteen")
      {
            return true;
      }
      else if (pNumber == "seventeen")
      {
            return true;
      }
      else if (pNumber == "eighteen")
      {
            return true;
      }
      else if (pNumber == "nineteen")
      {
            return true;
      }
      else if (pNumber == "twenty")
      {
            return true;
      }
      else
      {
            cout << "*** ERROR: the number string: " << pNumber << " :is not recognised ***" << endl;
            count2 = count2++;
      }
      return 0;
}

void printInt(int number)
{
      if (number == 1)
      {
            cout << "one";
      }
      else if (number == 2)
      {
            cout << "two";
      }
      else if (number == 3)
      {
            cout << "three";
      }
      else if (number == 4)
      {
            cout << "four";
      }
      else if (number == 5)
      {
            cout << "five";
      }
      else if (number == 6)
      {
            cout << "six";
      }
      else if (number == 7)
      {
            cout << "seven";
      }
      else if (number == 8)
      {
            cout << "eight";
      }
      else if (number == 9)
      {
            cout << "nine";
      }
      else if (number == 10)
      {
            cout << "ten";
      }
      else if (number == 11)
      {
            cout << "eleven";
      }
      else if (number == 12)
      {
            cout <<  "twelve";
      }
      else if (number == 13)
      {
            cout << "thirteen";
      }
      else if (number == 14)
      {
            cout << "fourteen";
      }
      else if (number == 15)
      {
            cout << "fifteen";
      }
      else if (number == 16)
      {
            cout <<  "sixteen";
      }
      else if (number == 17)
      {
            cout << "seventeen";
      }
      else if (number == 18)
      {
            cout << "eighteen";
      }
      else if (number == 19)
      {
            cout <<  "nineteen";
      }
      else if (number == 20)
      {
            cout <<  "twenty";
      }
      else
      {
            cout << number;
      }
}

Commented:
printInt needs to have a return type other then void in order to use it with cout.
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

Commented:
cout << printInt(count) << " successful calculations and " << printInt(count2) << " unsuccessful" << endl;

In the above line of code, you're trying to send the return value of printInt to cout, but printInt has a return type of void.

Author

Commented:
I had the exact same problem when i was trying to return it:

string convertString(int number)
if (number == 1)
{
return "one";
}

or isnt that how i should have been doing it??

Commented:
>>or isnt that how i should have been doing it??
You need to change the return type, before trying to return a value.

So change
void printInt (int number);

to

int printInt (int number);

Make sure you change it both in the function declaration and on the code implementation. (Both places).

Commented:
Correction:

Change
void printInt (int number);

to

std::string printInt (int number);

You need to include<string> for std::string usuage.

Author

Commented:
will that still allow is to output an integer or a string depending on it being above/below twenty??

BTW u guys rock, thanx for granting me some of ur time
int printInt (int number);
 
will work, you can have a

return number;

in the printInt function :)
you cant say
return "one";
you must return the variable

Author

Commented:
im fairly sure in knowing that you cant return a string into an integer.

Author

Commented:
will that still allow is to output an integer or a string depending on it being above/below twenty??

BTW u guys rock, thanx for granting me some of ur time

Author

Commented:
will that still allow is to output an integer or a string depending on it being above/below twenty??

BTW u guys rock, thanx for granting me some of ur time

Commented:
Rewrite the function like this:

std::string printInt(int number)
{
     if (number == 1)
        return std::string("one");
     else if (number == 2)
        return std::string("two");
     /*
        continue like this
     */
     else
     {
        char buffer[20];
        _itoa(number,buffer,10);
        return std::string(buffer);
     }
}

Now you can use

cout << printInt(10) << " " << printint(25);

This will give you:

ten 25

as output.

Important: Include <stdlib.h> at the top of your program.  The function _itoa is declared in there !  If you are not using Visual C++, let me know and I'll send you another function that will work there...  Or why the hell not:

// convert a number 'i' to at string
void itoa(int i, char* pbuff)
{
  sprintf(pBuff,"%d",i);
}

call the routine like this:

int a = 1204;
char pBuff = new char[20];
itoa(a,pBuff);
std::string str = std::string(pBuff);
delete pBuff;

Only follow these steps if you're not using VC++.  

Best Regards,
Tim Musschoot

Author

Commented:
printInt(count);
cout << " successful calculations and ";
printInt(count2);
cout << " unsuccessful" << endl;
cout << endl;

this was the code which corrected my problem. The void would not output inside a cout so i had to take it outside the cout.

Author

Commented:
Thanx man. u guys rock

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial