Getting an error for function

Hi guys, this assignment is due in an hour and I am trying to finish it. I am getting an "expected primary expression before "double"". What am I doing wrong?

#include <iostream>
#include <cstdlib>
#define TAX 0.925
using namespace std;
void input();
void calculation(double, double);
void output(double, double, double, double, double);
int main()
{
input();
calculation(double pizzas, double drinks);
output(double subtotal,double tax,double total);
system("pause");
return 0;
}

void input()
{
double pizzas, drinks;
cout << "Input the number of pizzas ordered: " << endl;
cin >> pizzas;
cout << "Input the number of drinks ordered: " << endl;
cin >> drinks;
return;
}

void calculation(double pizzas, double drinks)
{
double subtotal, tax, total;
subtotal = (pizzas * 10.99) + (drinks * 1.49);
tax = subtotal * TAX;
total = subtotal + tax;
return;
}

void output(double subtotal, double tax, double total)
{
cout << "Subtotal: " << subtotal << endl;
cout << "Tax: " << tax << endl;
cout << "Total: " << total << endl;
return;
}

Hi,

Please always use code tags:

http://www.cplusplus.com/articles/z13hAqkS/


Your functions don't do anything: They don't return a value. You need to make the parameters references, so that these values change in main.

1
2
void calculation(double& pizzas, double& drinks)
{


The same for the input function.

In the declaration of the functions before main, put names to the parameters - the same as in the function definition after main.

There is no need for a return statement in the functions, unless you want to exit the function early.

Edit: IF you have error messages post them here verbatim. At the moment, which double are you talking about?

Don't #define values, make them const variables instead.
Last edited on
Sorry, I messed up:

1
2
3
4
5
// const for things we don't change
// references for what we changed in main, need to declare these in main
void calculation(const double pizzas, const double drinks,
                        double& subtotal, double& tax, double& total;)
{
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
#include <iostream>
#include <cstdlib>
#define TAX 0.925
using namespace std;
void input();
void calculation(double& pizzas, double& drinks);
void output(double& subtotal, double& tax, double& total);
int main()
{
    input();
    calculation(double& pizzas, double& drinks);
    output(double& subtotal, double& tax,double& total);
    system("pause");
    return 0;
}

void input()
{
     double pizzas, drinks;
    cout << "Input the number of pizzas ordered: " << endl;
    cin >> pizzas;
    cout << "Input the number of drinks ordered: " << endl;
    cin >> drinks;
    
}

void calculation(double& pizzas, double& drinks)
{
    double subtotal, tax, total;
    subtotal = (pizzas * 10.99) + (drinks * 1.49);
    tax = subtotal * TAX;
    total = subtotal + tax;
}

void output(double& subtotal, double& tax, double& total)
{
     cout << "Subtotal: " << subtotal << endl;
     cout << "Tax: " << tax << endl;
     cout << "Total: " << total << endl;
     
}


I am still getting the same error.

Last edited on
Ok, getting there, you have half of it in code tags :+)

Check out the edits I made, and the new post .
1
2
3
4
5
 input();
    calculation(double& pizzas, double& drinks);
    output(double& subtotal, double& tax,double& total);
    system("pause");
    return 0;


this is the double error that im getting "expected primary expression before "double")
Last edited on
Show the exact error, word for word with the line number.

You need to declare all these variables in main, so there is something there to change.

Look at the tutorial at the top left of this page, try to understand about references.

Don't put the type in when calling a function.
Last edited on
1
2
calculation(double& pizzas, double& drinks);
output(double& subtotal, double& tax,double& total);


This is not the right way to call a function.
You need to declare the variables in main and pass it to the functions.
1
2
3
double pizzas = 0.0, drinks = 0.0, subtotal = 0.0, tax = 0.0, total = 0.0;
calculation(pizzas, drinks);
output(subtotal, tax, total);


Also the variables pizzas and drinks in your input function are not visible outside the function. Better is to pass the variables as parameters to the function like this.
void input(double& pizzas, double& drinks
Topic archived. No new replies allowed.