Function output and User input

Hello guys, i am trying to create a function that will get the inputs from the GetInput function and use the values in the calculation function. this is how far i got. your advice will really help alot.

thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

double GetInput(double r, double l, double c, double t);
double Caculation(double r1, double l1, double c1, double t1);

int main()
{
	GetInput();
	return 0;
}
  double GetInput(double r, double l, double c, double t)
{
	do
	{
		cout << "Enter R (k): ";
		cin >> r;
	}while( r <= 0);

	do
	{
		cout << "Enter L (mH): ";
		cin >> l;
	}while( l < 0);

	do
	{
		cout << "Enter C (nF): ";
		cin >> c;
	}while( c < 0);

	do
	{
		cout << "Enter Maximum time (us): ";
		cin >> t;
	}while( t == 0);

double Caculation(double r1, double l1, double c1, double t1)
{
  
}	
Your GetInput function requires four parameters, but you provide none when you call it in main(). It also returns a double, but you do not return anything from the function (and you don't seem to want to do anything with it in the main() function). There's also a missing brace on line 35.

Assuming you're going to call Calculation separately, you should consider changing your GetInput function to receive reference variables. This will allow you to modify the original arguments. That way, you can write
1
2
3
double r(0.0), l(0.0), c(0.0), t(0.0);
GetInput(r, l, c, t);
Calculation(r, l, c, t);


Little nit-pick:
You should really rename your variables (and probably function names) to be more clear. I am guessing your r, l, and c variables are supposed to be Resistance (you forgot to write ohms on line 14 if so), Inductance, and Capacitance.
Now, unless one has studied Physics, one may not be able to recognize these variables and be confused as to what they're there for.
Last edited on
what i am trying to do is create three separate functions one for the inputs, calculation and output including the main function. for the GetInput function i was trying to make the message show up and the user will have to enter the values for R, L, C and T and those values will then be used in the calculation function. I dont get what to put in the main function either
1
2
 GetInput(r ,l ,c ,t) = Calculation;
 GetInput(r ,l , c, t); 


when i put return values at the end of each do loop it stops a the R and ends the program.
I don't really know what you want to return from GetInput, but you may only return one value. This is why I suggest using reference variables:
1
2
3
int a(0);
int& b(a);
b = 4; // a will also become 4 


So your prototype would look something like:
 
void GetInput(double& res, double& induct, double& capac, double& t_max);

Note that even though these are reference variables, you don't have to change a thing in the definition.

Try writing your GetInput and Calculation functions so that you may write this in main():
1
2
3
4
5
6
7
8
9
10
11
12
int main(){
   double R(0.0), L(0.0), C(0.0), t(0.0);
   GetInput(R, L, C, t);

   cout
      << "Resistance: " << R << " kilohms.\n"
      << "Inductance: " << L << " milliHenry.\n"
      << "Capacitance: " << C << " nanoFarads.\n"
      << "Maximum Time: " << t << " microseconds.\n"
      << "Calculation: " << Calculation(R, L, C, t) << '\n'
   ;
}
Last edited on
Thanks for the help I kinda get what your saying. i will give it a try myself.

thanks.
Topic archived. No new replies allowed.