Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 131,697 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,511 people online right now. Registration is fast and FREE... Join Now!




double triple quad functions

 
Reply to this topicStart new topic

double triple quad functions, double triple quad

Mo821
post 11 Dec, 2005 - 01:07 PM
Post #1


New D.I.C Head

*
Joined: 10 Dec, 2005
Posts: 8


My Contributions


1. take 4 arguments type double ( could be passed by valur or reference
2. computes double (twice number) triple 3 ( three times) and quadruple (4 times)
3. uses 2nd, 3rd, and 4th arguments to "return" the double, triple, and quad.

B. 1.enter number
2. call yourdoubletriplequad function with numbers in first argument
3.print to screen double,triple,and quad values of entered number

# include <iostream>
using namespace std;

int doubleTripQuad (double, double&, double&, double&);

int main ()

{
double dbl, dbl2, dbl3, dbl4;
cout << "Please enter a number: ";
cin >> dbl >> dbl2 >> dbl3 >> dbl4;

return 0;
}

int doubleTripQuad (double dbl, double& dbl2, double& dbl3, double& dbl4)

{
dbl = 1 * 1;
dbl2 = 1 * 2;
dbl3 = 1 * 3;
dbl4 = 1 * 4;
}

your help in fixing this would be most appreciated
User is offlineProfile CardPM

Go to the top of the page


Amadeus
post 11 Dec, 2005 - 02:01 PM
Post #2


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,163



Thanked 32 times

Dream Kudos: 25
My Contributions


CODE

# include <iostream>
using namespace std;

double doubleTripQuad (double, double &, double &, double &);

int main ()

{
double dbl, dbl2, dbl3, dbl4;
cout << "Please enter a number: ";
cin >> dbl;
doubleTripQuad(dbl,dbl2,dbl3,dbl4);
cout<<"The original value was "<<dbl<<" and the returned values are "<<dbl2<<","<<dbl3<<","<<dbl4<<endl;
return 0;
}

double doubleTripQuad (double dbl, double &dbl2, double &dbl3, double &dbl4)

{
dbl2 = dbl  * 2;
dbl3 = dbl  * 3;
dbl4 = dbl * 4;
}

As an FYI, you had already opened a thread with this topic...I'll delete that one, but in the future, please try to keep all related material to the original thread.
User is online!Profile CardPM

Go to the top of the page

damoun
post 13 Dec, 2005 - 05:51 AM
Post #3


New D.I.C Head

*
Joined: 6 Aug, 2005
Posts: 36

I am not really sure what you are trying to do but note that:

1) your function, doubleTripQuad(), is declared to be returning an int value, so in the fuction body you must have a return statment (an expressin following the keyword return).
note that if you omit the return statment most compilers will issue an error, but some will not and will return a random value.
User is offlineProfile CardPM

Go to the top of the page

damoun
post 13 Dec, 2005 - 05:54 AM
Post #4


New D.I.C Head

*
Joined: 6 Aug, 2005
Posts: 36

my bad, your fuction is returning a double.
if your function will only modify the vale of some varibles in the calling function, the the return type of the function should be declared void.
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 13 Dec, 2005 - 06:30 AM
Post #5


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,163



Thanked 32 times

Dream Kudos: 25
My Contributions


Geez, I must be getting sleepy while posting these days...that two mistakes in two days! smile.gif

damoun is correct, the return value of the function should have been modified to void...can't believe I misssed making that change. smile.gif
User is online!Profile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/20/08 08:48AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month