Total Running Cost and Enum data types

I have to write a program that takes in a product name and cost, then outputs it and also outputs the total running cost, unless the user input was q. My teacher wants us to use multiple functions in our program and it seems like she even wants it for the total running cost which is where i'm having problems. it keeps giving me the error that my variable cost isn't an integral or enum data type so i can't use it, but I read in my book about enums and I just don't see how i would implement that there mostly, because of the if statement. Also, I did look through the forums, but i didn't find anything that worked for me.

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
 #include <iostream>
#include <iostream>
#include <cstring>
#include <cmath>
#include <limits>

using namespace std;
float runningTotal(double,double);
char menuLoop();
void menu();



int main()
{
    menu();


    return 0;
}

double runningTotal(double *cost, double *multipleCost)
{


    if(cost > 0)                              
    {
   	 multipleCost += cost;     // here is where i'm getting my error
    }             // error: expression must have an integral or unscoped data type




    return *multipleCost;
}


char menuLoop()
{
    char userInput[20];

    double cost, multipleCost = 0;

    cin.get(userInput,'\n');
    cin >> cost;
    putchar(tolower(userInput[20]));
    
    if (userInput[20] = 'q')
    {
   	 cout << runningTotal(&cost, &multipleCost) << '\n' << "Thank You for shopping with us\n";
    }else {
   	 cout << "The product: " << userInput << " and the cost: " << cost << '\n'
   		  << "Your running total is:" << runningTotal(&cost, &multipleCost) << endl;
    }
    
    return userInput[20];
}

void menu()
{
    int cost;
    cout << "Do one of the following\n"
   	  << "Input a product name and cost  or to quit the program enter Q\n";
    menuLoop();
}
Last edited on
multipleCost += cost; you forgot to dereference them


out of bounds :
if (userInput[20] = 'q') ==

putchar(tolower(userInput[20]));

return userInput[20];

you should enable all compiler warnings to catch small but terrible errors
Last edited on
@nvrmnd

It's working, thank you very much I was getting really frustrated with it.
Topic archived. No new replies allowed.