Just learning Fuctions, what should i think of when making em?
I understand how functions work, but if i'm unable to utilize it in a simple program, i guess i dont entirely understand it.
Anywho, i have to make a program where the users enter in an upper limit and a lower limit and the resrictions are....
y=-x when x<0
y=x^2 when 0<=x<=2
x>2 when y=4
Also the user gets to enter in an amount to increment.
heres an example, the user enters in -3 for lower and 3 for upper, it should display this...
xvalue yvalue
-3 3
-2.50 2.50
...... ......
..... ......
0 0
.50 .50
..... .......
..... ......
2 4
2.5 4
3 4
i got this far in my code...
Code:
float slope(int x, int y);
using namespace std;
void main()
{ float upnum, lownum, inc, a;
cout << "Slope Function Program" << endl;
cout << "Enter Lower Limit: " << endl;
cin >> lownum;
cout << endl;
cout << "Enter Upper Limit: " << endl;
cin >> upnum;
cout << endl;
cout << "Enter Increment: " << endl;
cin >> inc;
cout << endl;
cout << left << setw(8) << "X Value" << " " << left << setw(8) << "Y Value" << endl;
cout << "--------" << " " << "--------" << endl;
a = slope(lownum,upnum);
cout << a << endl;
}
float slope(float &x, float &y)
{
if(x<0)
{
y = x * (-1);
}
else if(x>=0 || x<=2)
{
y = sqrt(x);
}
else if(x>2)
{
y = 4;
}
return(x,y);
}
So can anyone tell me how many fucntions should i create and what should i be thinking about when making this program? Because i have a problem of how the program will work in my mind. Its not organized in my mind but all jumbled, which makes it hard to get it down to paper.