Currently I'm trying to run a program where you either pick an integer or a decimal and based on that your number gets manipulated. I was told by my Prof to use function overloading to get this to work. But every time I try to compile it it gives me 101 warnings and 2 errors saying: 'pick' must return a value
. Am I not declaring it properly? I followed the template from my textbook and a few I found online but can't get it to work.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
//Declarations
int userInt;
double userFloat;
char selection, ans;
static double counterInt, counterFloat;
//Prototypes
int pick(int);
double pick(double);
//Defaults
counterInt = 0;
counterFloat = 0;
ans = 'Y';
//Game
do
{
cout << "Please choose an integer or a decimal number by typing in i or d" << endl;
cin >> selection;
if(selection == 'i')
{
cout << "Please enter an integer" << endl;
cin >> userInt;
cout << pick(userInt);
counterInt++;}
else
{
cout << "Please enter a decimal" << endl;
cin >> userFloat;
cout << pick(userFloat);
counterFloat++;}
//Play Again?
cout << "Would you like to play again? Please enter Y or N" << endl;
cin >> ans;
}
while ((ans == 'Y') || (ans == 'y'));
//End Game
if ((ans != 'Y') && (ans != 'y'))
{
cout << "Thank you for playing! You picked integers: " << counterInt << " times and you picked decimals: " << counterFloat << " times." << endl;
}
return 0;
}
//Function Overload
int pick(int number)
{
if( number % 7 == 0)
{
cout << setw(7) << "7777777" << setw(7) << number << endl;
}
else
{
cout << setw(7) << "*******" << setw(7) << number << endl;
}
}
double pick(double number)
{
cout << setw(6) << "The square root of the number " << number << " is: " << setprecision(3) << pow(number,.5) << endl;
}