Returning two values

Going to preface this with that it is hw so obviously I can't ask for an answer, just hoping for some assistance to get pointed in the right direction. The problem is I'm having trouble pulling both the discount amount and the overall price from the second function. I can get one or the other, so I'm assuming it has to do with not being able to pull both values with a return statement. Could someone point me in the direction of info that will help to solve this?

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
40
41
42
43
44
45
46
47
48
49
50
51
52
/*************************************************************
****Change only 1) function calcDiscount, 2) its prototype ***
****and 3) place your name in signature function!*************
**************************************************************/

#include <iostream>
#include <iomanip>
using namespace std;
#define DISC_RATE 0.1

//Function prototypes
void signature(void);
double calcDiscount(double);

int main()
{
 // Declare variaables
 double amtOwing, discount;
 
 //Input amouont owed
 cout << "Enter amount owed: " ;
 cin >> amtOwing;
 
 //Calculate discount and update amount owing
 discount = calcDiscount(amtOwing);
 
 //Output discount and undated amount owed
 cout << setprecision(2) << fixed;
 cout << "Amount of Discount: " << discount << endl;
 cout << "Amount Owed: " << amtOwing << endl;
 
 signature();
 return 0;
}
///////////////////////////////////////////////////////////////
double calcDiscount(double owe)
{
 /*Pre: owe - amount owed
 Post: Amount of discount
 Purpose: calculate discount and update amount owed to reflect discount*/
 
 double disc;
 disc = DISC_RATE * owe;
 //Update amount owed
 owe = owe - disc;
 
 return disc;
}//////////////////////////////////////////////////////////
void signature()
{
 cout << "Programmed by: " << " ";
}
Pass amount owed by reference.

1
2
3
4
5
6
7
8
double calcDiscount(double&);
// ...
double calcDiscount(double& owe)
{
    // ...
    owe = owe - disc ;
    // ...
}
one alternative way

struct retme
{
double d1;
double d2;
};

retme calcDiscount(...
{
...
retme r;
r.d1 = something;
r.d2 = something else;
return r;
}

retme tmp;
tmp = calcDiscount(stuff);
use(tmp.d1);
use(tmp.d2);

Topic archived. No new replies allowed.