Results 1 to 5 of 5

Thread: Use Data From One Function To Another

  1. #1
    Join Date
    Nov 2009
    Posts
    50

    Use Data From One Function To Another

    Hello, I am learning Programming in C++ and I want to Use Data From One Function To Another. I have tried to achieve it, but failed to perform it. If you know the details from which I can able to perform it, then please provide details for it. I will be thankful to you.

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Use Data From One Function To Another

    Hello, I have used the code below and performed the use of data from one function to another:
    Code:
    double funtriangle();
    
    double funtriangle()
    {
    	double num1;
    	double num2;
    	double num3;
    	double add1;
    	double add2;
    	double add3;
    	
    	cout<<"Side 1: ";
    	cin>>num1;
    	while(num1<=0)
    	{
    		cout<<"Side lengths must be positive."<<endl;
    		cout<<"Side 1: ";
    		cin>>num1;
    		cout<<endl;
    	}
    
    	cout<<"Side 2: ";
    	cin>>num2;
    	while(num2<=0)
    	{
    		cout<<"Side lengths must be positive."<<endl;
    		cout<<"Side 2: "; 
    		cin>>num2;
    		cout<<endl;
    	}
    
    	cout<<"Side 3: ";
    	cin>>num3;
    	while(num3<=0)
    	{
    		cout<<"Side lengths must be positive."<<endl;
    		cout<<"Side 3: ";
    		cin>>num3;
    		cout<<endl;
    	}
    
    	add1=num1+num2;
    	add2=num2+num3;
    	add3=num1+num3;
    
    	if ((add1>num3)&&(add2>num1)&&(add3>num2))
    	{
    		cout<<"The values of the sides equal a triangle."<<endl;
    		cout<<endl;
    	}
    	else
    	{
    		cout<<"The values of the sides do not equal a triangle."<<endl;
    		cout<<endl;
    	}
    	
    	return(0);
    }

  3. #3
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Use Data From One Function To Another

    I think that you must need to create a signatures of the function as below:
    Code:
    bool test(double side1, double side2, double side3);
    and as below
    Code:
    double check(double side1, double side2, double side3);
    From this you will able to do what you want.

  4. #4
    Join Date
    May 2008
    Posts
    2,012

    Re: Use Data From One Function To Another

    I will suggest you to read the books on C++ for getting the result on this. I am not having that much knowledge about c++, I am having knowledge about java. But, I think you can get the solution by referring the books below:
    • C++ GUI Programming with Qt 3
    • C++ Reference Guide
    • ZooLib Cookbook
    • C++ in action
    • Teach Yourself C++ in 21 Days

  5. #5
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Use Data From One Function To Another

    Hello, I think you will able to get the solution for your problem if you simply make use of the Friend keyword. I have read that by using this keyword you can make use of the one function data to the another and get your program to be solved. I have not yet used it, but you can try for making one variable and get your solution.

Similar Threads

  1. c# function equivalent to gettime function in javascript
    By Omaar in forum Software Development
    Replies: 4
    Last Post: 10-03-2010, 10:44 PM
  2. Replies: 5
    Last Post: 27-02-2010, 07:52 PM
  3. How does abstract function differs from virtual function?
    By Maddox G in forum Software Development
    Replies: 5
    Last Post: 29-01-2010, 11:32 AM
  4. Replies: 5
    Last Post: 19-03-2008, 11:41 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,719,064,061.29902 seconds with 17 queries