/*Program i made to multiply two numbers; then the user decides if they should
round the values up or down. based on the user input, if the string is equal
to up, 1 is assigned to the value round, else if the string is equal to down, 0
is assigned to the value round. If the user enters something other than up or down
no rounding is assumed. These values are then passed through the function
mult for an answer.*/
#include <iostream>
#include <cmath>
usingnamespace std;
double mult(double a, double b, double c, double r); // LINE 12
int main()
{
cout << "First number: " << endl;
double fnum;
cin >> fnum;
cout << "Second number: " << endl;
double snum;
cin >> snum;
cout << "Would you like to round up or down the answer?";
string rounding;
cin >> rounding;
double round;
if (rounding.compare("up"))
round = 1;
elseif(rounding.compare("down"))
round = 0;
else
round = 2;
cout << mult(fnum, snum, round); // LINE 33
cin.get();
cin.get();
return 0;
}
double mult(double a, double b, double c, double r)
{
if (c == 0)
{
r = floor(a * b);
}
elseif (c == 1)
{
r = ceil(a*b);
}
else
{
r = a*b;
}
return r;
}
I thought it was possible to not pass a value assuming i declare the value in the function header.
When I had line 43 set to "double mult(double a, double b, double c, double r = 2)
it still wouldn't work..
I guess i'm asking if its possible to pass less values to the functions or pass a NULL value to a function(since really i only want 3, the 4th is just the return value);
it's quite possible that I didn't, i was scrambling between variations of the code trying to get my brain into C++ mode (usually start off by writing something random based off the newest stuff I learned the last time i programmed).
Thanks for helping by the way, truly appreciate it.