In: Computer Science
Language C++
*note* Your function count should match those given in the description; you have no need for extra functions beyond that, and you should not have less.
-Write a function, doTheRegression(), that takes as input a variable of type integer and returns a value of type double. It computes and returns 80% of the value given as the amount after reduction.
-In your main function, write code that asks the user what the original amount is, and if they are splitting profits this week. You may assume that the user always enters reasonable input ("yes" and "no" is enough).
-Input should be done one question at a time.
-If the user answers "no", call function doTheRegression() on the original value to get an appropriate answer.
-If the user answers "yes", ask the user for the number of people splitting the profits.
-If the user answers "yes", call an overloaded version of function doTheRegression() that takes two inputs of type integer; this function takes the exact division of the original amount and the number of people splitting profits, and then returns 90% of the value given.
-Your code should run at least 2 times, so that it can properly be tested.
-Output should be accurate to 1 decimal place.
-Use pre existing functions as necessary to make sure that all excess input is being discarded, every time the user finishes inputting input.
Sample Output:
Original amount: 24
Are you splitting profits? no
Reduced value: 19.2
Original amount: 26
Are you splitting profits? Yes
How many people? 3
Reduced value: 7.8
*Explanation* 80% of 24 is 19.2, the first case should be calling the original function. 26/3 is 8.6 repeating, and 90% of that leaves 7.8; the second case should be calling the overloaded function.
Code
#include<iostream>
using namespace std;
double doTheRegression(int x)
{
double v =(double) (x*80)/100;
return v;
}
double doTheRegression (int x,int y)
{
double v= (double) x/3;
v= (v*90)/100;
return v;
}
int main()
{
cout<<"Enter original amount :";
int x; //input the original amount
cin>>x;
cout<<"are you splitting profits? ";
string s;
cin>>s; //input splitting or not
if(s=="yes") //if yes call the overloaded function
{
cout<<"how many people? ";
int p;
cin>>p;
double d= doTheRegression (x,p);
cout<<"Reduced value: "<<d;
}
else //if no call the doTheRegression
{
double d=doTheRegression (x);
cout<<"Reduced value: "<<d;
}
return 0;
}
Terminal Work
.