Feb 23, 2016 at 7:24am UTC
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;
}
Feb 23, 2016 at 7:35am UTC
Hi,
Please always use code tags:
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 Feb 23, 2016 at 7:38am UTC
Feb 23, 2016 at 7:43am UTC
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 Feb 23, 2016 at 7:44am UTC
Feb 23, 2016 at 7:45am UTC
Ok, getting there, you have half of it in code tags :+)
Check out the edits I made, and the new post .
Feb 23, 2016 at 7:49am UTC
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 Feb 23, 2016 at 7:50am UTC
Feb 23, 2016 at 7:57am UTC
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 Feb 23, 2016 at 8:16am UTC