error !!

this is where my error is occuring:

void runMenu(double allItems, int & itemId)
{
int option;
string word, msg = "Sale Record: ( 101024, 199.95, D, 1)"; // displaying the message
do
{

msg="";
switch(option)
{
case 1: // calculate the item cost
double itemCost;
if (calculateItemCost ( double itemPrice, char discountType, unsigned quantity))
msg+= "** Item cost " + toString(itemCost)+ " was added.";
else
msg+= "** No item was calculated.";
break;
case 2: // Display the total cost
if (displayTotalCost ( double totalCost, unsigned recordNum, bool aborted));
msg+="**displayTotalCost " + toString(totalCost) + "was added.";
else
msg+="**Total cost not displayed ";

break;
case 3:
if (readSaleRecord ( unsigned & itemId, double & itemPrice, char & discountType, unsigned & quantity));
msg+="** Sale record was added.";
else
msg+= "** No sale record read.";
break;
}
}


And what is the error?

I see that your switch statement depends on the value of option, which you never set, so it's some random value. Is that meant to happen?

Why do you give msg a value at the start, and then at the start of the do-while loop, change that value to blank? Why not just make it blank at the start?

Please, please, use braces { } for your if and else statements, so we can see what you meant to do and not just what you're actually doing.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void runMenu(double allItems, int & itemId)
   { 
    int option=0;
    string word, msg = "Sale Record: ( 101024, 199.95, D, 1)"; // displaying the message
    do 
    {   
        option=numericalMenu(msg);
            msg="";                   
          switch(option)
           {
                   case 1: // calculate the item cost
                   double itemCost;
                   if (calculateItemCost ( double itemPrice,  char discountType, unsigned quantity))
                   cout << "\nProcessing task " << option << "...\n"; 
                   msg = '0' + option;
                   msg += " was last selected\n";
                   system("pause");
                   break;


line 13: expected primary-expression before "double"
expected primary-expressions before "char""
expected primary-expressions before "unsigned"
You shouldn't be specifying the type when you call a function.

The call should look something like this:
 
if(calculateItemCost(itemPrice, discountType, quantity))


Even then, that's only really going to do something useful if that's a boolean returning function which, judging by it's name, it isn't.
calculateItemCost ( double itemPrice, char discountType, unsigned quantity)
That is not how to call a function. I expect you meant this:
calculateItemCost ( itemPrice, discountType, quantity)
Last edited on
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
 void runMenu(double allItems, int & itemId)
   { 
    int option=0;
    string word, msg = "Sale Record: ( 101024, 199.95, D, 1)"; // displaying the message
    do 
    {   
        option=numericalMenu(msg);
            msg="";                   
          switch(option)
           {
                   case 1: // calculate the item cost
                   double itemCost;
                   (calculateItemCost (  itemPrice, discountType, quantity))
                   cout << "\nProcessing task " << option << "...\n"; 
                   msg = '0' + option;
                   msg += " was last selected\n";
                   system("pause");
                   break;
                         case 2: // Display the total cost
                         cout << "\nProcesssing task " << option << "...\n";
                         (displayTotalCost ( totalCost, recordNum));
                         msg = '0' + option;
                         msg += " was last selected\n";
                         system("pause");
                         break;
                               case 3: // list sale records
                               cout << "\nProcessing task " << option << "...\n";
                               (readSaleRecord (  &itemId, &itemPrice, &discountType, &quantity));                         
                               msg = '0' + option;
                               msg += " was last selected\n";                    
                               system("pause");
                               break; 
                               }
                           }


im getting the following error now:
`itemPrice' undeclared (first use this function)
`discountType' undeclared (first use this function)
`quantity' undeclared (first use this function)
`totalCost' undeclared (first use this function)
`recordNum' undeclared (first use this function)
You need to declare them within the scope of the runMenu function and assign values to them. Alternatively, you could pass them as parameters to the runMenu function.

Depending on how calculateItemCost is written, you may also need to assign the returned value to a variable.
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
#include<iostream>
#include<sstream>
#include<cmath>
using namespace std;
const string VERSION  = "JEWELLERY";
const int MAXSIZE = 1000; // maximum number of records allowed
       
       
// function prototypes
void runMenu();
void displayMenu();
void clrscr();
void pause();
int numericalMenu(string);
double calculateItemCost ( double [],  char [], unsigned []);
void displayTotalCost ( double [], unsigned [] );
int readSaleRecord ( unsigned [], double  [], char  [], unsigned  []);

int main() 
{
    double option;
    double allItems[MAXSIZE];
    int discountRate;
    return 0;
}

    void runMenu( )
   { 
    int option=0;
    string word, msg = "Sale Record: ( 101024, 199.95, D, 1)"; // displaying the message
    do 
    {                    
          switch(option)
           {
                   case 1: // calculate the item cost
                   double itemCost;
                   cout << "\nProcessing task " << option << "...\n"; 
                   msg = '0' + option;
                   msg += " was last selected\n";
                   system("pause");
                   break;
                         case 2: // Display the total cost
                         cout << "\nProcesssing task " << option << "...\n";
                         msg = '0' + option;
                         msg += " was last selected\n";
                         system("pause");
                         break;
                               case 3: // list sale records
                               cout << "\nProcessing task " << option << "...\n";                         
                               msg = '0' + option;
                               msg += " was last selected\n";                    
                               system("pause");
                               break; 
                               }
                           }                   


  while(option!=0);
  }
     void clrscr() //clear screen
     {
       system("cls");
     }    
                void pause() //stops
                {
                  system("echo.");
                  system("echo.");
                  system("pause");
                }
                          void exit() //exit
                          {
                            exit(0);
                          }
                                   void displayMenu(string msg) //displays menu
                                   {
                                     clrscr();
                                     cout << msg << "\n             *** JEWELLERY ***\n";
                                     cout << "\n-------------------- MAIN MENU --------------------\n";
                                     cout << "\n1. Calculate Item cost";
                                     cout << "\n2. Display the total cost";
                                     cout << "\n3. List the sale records";
                                     cout << "\n4. Calculate the standard deviation";
                                     cout << "\n---------------------------------------------------\n";
                                     cout << "\nYour Choice => ";   
                                   }

//-----------------------------------------------------------------------------------------------------------------------------------------------------------

//calculate the item cost
double calculateItemCost( double itemPrice, char discountType, unsigned quantity, double itemCost)
{
       cout << "Enter itemPrice: ";
       cin >> itemPrice;
       cout << "Enter discountType: ";
       cin >> discountType;
       cout << "Enter quantity: ";
       cin >> quantity;
       itemCost = itemPrice * discountType * quantity;
       cout << "The itemCost is " << itemCost;
       
       return 0;
       }
       
// display the total cost
void displayTotalCost ( double totalCost, unsigned recordNum, bool aborted)
{
     if ( recordNum >0)
     cout << "\ndisplayTotalCost: \n";
     else ( recordNum <0);
     cout << "Input terminated by invalid data at record";
     
     return;
}

// display the sales record
int readSaleRecord ( unsigned & itemId, double & itemPrice, char & discountType, unsigned & quantity)

{
    cout << "Enter itemId: ";
    cin >> itemId;
    cout << "Enter itemPrice: ";
    cin >> itemPrice;
    cout << " Enter discountType:";
    cin >> discountType;
    cout << " Enter quantity: ";
    cin >> quantity;
         
         system("PAUSE");
         
         return true;
}
    
    

    
    
    


ít has compiled however failing to run
It does run. Let's take a look at what you've programmed to happen.

1
2
3
4
5
6
7
int main() 
{
    double option;
    double allItems[MAXSIZE];
    int discountRate;
    return 0;
}


So, the program starts here, at main. You create a double, called option, and then you create an array, and then you create an int called discountRate, and then your programme ends. It does exactly what you programmed it to do.
ít has compiled however failing to run

I doubt that. It'll be running, just not how you want.

Don't forget, your program starts at main.

In main, you currently:
- Declare a double
- Declare an array of double
- Declare an integer
- Exit the program

You're not calling any functions in there.
Last edited on
NIINNNIIINNNN... JAR!
Hahaha. Damn you.
Topic archived. No new replies allowed.