function that returns character

Hello people. I got a long one for you...i think.
Well work here is supposed to be:
A function named menu that returns a character and does not accept any parameters. This function will display:
Welcome to <your name>’s Space Travel Company
(M)ost Powerful Calculation
(D)iscount Calculation
(H)ow Many Calculation
(Q)uit
Please enter the option (M,D,H, or Q)

my problem is taht I have nearly all of it done but i am to have a function called MENU that returns a character and does not accept any paramaters.

just as well the menu and such is supposed to loop as you can see from the "if" and "else if" statements I got in here.

Also, the 'n' that i put in front of the characters were just to fill the gap and make it stop telling me they weren't being initialized.

any help would be greatly appreciated. Thanks in advance.



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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
 //Skyler Lopez-Maldonado
//CSCI1010
//Menu functions
//september 20 2013


#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

// Function declarations, variables are passed by reference
void mostPowerful(double &, double &, double &, double &, int &);
void discountResults(double &, double &, double &, double &);
void howMany(double &, double &, int &, double &);
char menu(char);

int main() {
    
   double power1;   // Power measurement 1
   double power2;   // Power measurement 2
   double power3;   // Power measurement 3
   double max = 0;  // Maximum power measurement, initialized to zero
   int num = 0;     // Number representing which jetpack is the most powerful
   
   double price;    // Price variable
   double discount; // Discount percentage
   double discountAmount = 0;  // Amount taken off as discount
   double discountPrice = 0;   // Final discounted price
   
   double money;    // Amount of money available
   double cost;     // Cost of item
   int numAvail = 0;      // Number of items that can be purchased
   double moneyLeft = 0;  // Money leftover from purchase
   char choice = 'n';
   char m = 'n',d = 'n',h = 'n',q = 'n';
   // Each of these sections that ask for user input should be integrated into
   // the menu function. A prototype for the menu function is provided above,
   // but the function itself is nearly complete.
 
   cout << "Welcome to Skyler Lopez's Space Travel Company" << endl;
	   cout << "(M)ost powerful Calculations'" << endl;
	   cout << "(D)isount calculations" << endl;
	   cout << "(H)ow many calculations" << endl;
	   cout << "(Q)uit" << endl;
	   cout << endl;
	   cout << "Please enter the option (M, D, H, or Q)";
	   cout << menu(choice); //needs to be initialized!!! doesn't want to work!
	   

if (choice = m)
{
   cout << "Please enter 3 power output measurements in MW: "<< endl;
   cin >> power1;
   cin >> power2;
   cin >> power3;
   
   mostPowerful(power1, power2, power3, max, num);
   cout << "The largest power output is " << max << " and is Jetpack number is "
      << num << endl << endl;
}

else if (choice = d)
{
   cout << "Please enter a price and a discount amount: ";
   cin >> price;
   cin >> discount;
   
   discountResults(price, discount, discountAmount, discountPrice);
   cout << "The discount amount is " << discountAmount 
        << " and the discounted price is " << discountPrice << endl << endl;
}

else if (choice = h)
{
   cout << "Please enter amount available and cost of each: ";
   cin >> money;
   cin >> cost;
   
   howMany(money, cost, numAvail, moneyLeft);
   cout << "You can buy " << numAvail << " and have " 
        << moneyLeft << " left over." << endl << endl;
  

    cin.get();   
    cin.get();                   
    system ("PAUSE");
	return 0;
}while (choice != q);
}


void mostPowerful(double &p1, double &p2, double &p3, double &max, int &num) {
     
     // Comparison to determine the maximum power output and to set it to 
     // the max variable as well as setting the num variable based on the max
     if ((p1 > p2) && (p1 > p3)) { 
        max = p1;
        num = 1;
     } 
     else if ((p2 > p1) && (p2 > p3)) {
        max = p2;
        num = 2;
     }
     else {
        max = p3;  
        num = 3;
     }          
}
    
void discountResults(double &p, double &d, double &da, double &dp) {
     
     // Discount amount equlas price times discount
     da = p * d;
     
     // Discount price equals price minus discount amount
     dp = p - da;                               
}
    
void howMany(double &m, double &c, int &na, double &ml) {
     
     // temp is a variable to hold the value of money divided by cost
     double temp;
     temp = m / c; 
     
     // The value stored in temp is cast to an integer to determine the 
     // number available to purchase
     na = (int)temp;  
     
     // Money left is determined by subtracting the cost times number available
     // to purchase from the amount of money available
     ml = m - na * c; 
}    
   
char menu(char choice)
{
   char decision;
   decision = choice;
	   return decision;

}
According to the instructions, the menu function should do all the printing, which you're doing in main().

Also, your conditions on lines 51, 63 and 74 aren't really conditions.
You're using the assignment operator (=).
What you meant to use was the binary comparison operator (==).
Also, what's the problem? You said that you need a function named "menu", which returns a char and takes no parameters, so where's the problem?
if you want a function that accepts no parameters, you simply have to put void inside parenthesis in the function prototype and definition, or you can just leave it blank, and same if you want a function that returns nothing:

char menu ( void ); is the same as char menu();


As the instruction says you should have a function that accepts no parameters and returns a char, you can do something like:

1
2
3
4
5
6
7
char menu ( void )
{
    char decision;   
    /* print the menu ( the code you've written at line 41 to 48 ) */
    /* prompt for the decision ( cin >> decision )*/
   /* return decision */
}

so in you main function you should have a char variable that store the return value of menu, then process it:
1
2
char a = menu(); // call menu function and store the return value of it to a
/* Process variable a here */


Another thing:
cout << menu(choice); //needs to be initialized!!! doesn't want to work!
you should delete this line, it's pointless !!!
Last edited on
Topic archived. No new replies allowed.