I am a newbie to C++ and am working on a simple program with an overloaded function GetNumber. If GetNumber is sent a bool argument it returns 0 or 1, if GetNumber is sent a integer argument it multiplies that number by itself then returns the product. Now here is my code that doesn't work:
Now it compiles with no errors and no warnings, but when ran the program doesn't save any of the user inputs into the variables input and number. If you can tell me what I am doing wrong i would appreciate it greatly!Code:#include <iostream> #include <conio.h> //Simple Overloading program int GetNumber(bool testbool); int GetNumber(int num); using namespace std; int main() { bool input= false; int output=0, number=0, product=0; // prompt for user input and store in input and number cout << "Enter true or false..."; cin >> input; cout << "Enter an integer..."; cin >> number; // call the overloaded function using their seperate parameters output = GetNumber(input); product = GetNumber(number); // output the solutions cout << " Your true and false answer converted to..." << output << endl << "Your integer was squared and the product is..." << number; getch(); return 0; } int GetNumber(bool testbool) { int convrt=0; if (testbool) // tests for a nonzero answer convrt = 1; else convrt = 0; return convrt; } int GetNumber(int num) { return num * num; }



LinkBack URL
About LinkBacks



my spider-sense be tingling.