Hello, I'm trying to figure out this problem I'm having so that I can finish the last portion of my programming lab for school. I know I've fixed this error before, I just can't seem to do it this time. Can anyone please point me in the right direction? (Also, it's a debugging lab, hence only comments being about what I've changed)
#include<iostream> //removed .h
#include<conio.h>
#include<string> //removed .h
usingnamespace std; //added this
class Order
{
friend Order yearEndTotal(Order summary, Order oneOrder); //added friend
private:
char customerName[20];
int orderQuantity;
public:
Order();
void setValues(char customerName[], int orderQuantity); //added void and paramaters
void displayValues(); //added void
};
Order::Order()
{
strcpy(customerName,
"Total");
orderQuantity=0;
};
void Order::setValues(char customerName[], int orderQuantity) //added the parameters, and Order::
{
cout << "Enter customer name ";
cin >> customerName;
cout << "Enter quantity ordered: ";
cin >> orderQuantity;
}
void Order::displayValues()
{
cout << customerName[20] << " ordered " << orderQuantity << " items." << endl; //added a bunch of <<
}
Order yearEndTotal(Order summary, Order oneOrder)
{
summary.orderQuantity += oneOrder.orderQuantity; //added +
return(summary);
}
void main()
{
constint ORDERS = 3; //changed 10 to 3
Order anOrder[ORDERS];
Order summary;
int x;
for(x=0; x<ORDERS; ++x) //removed ;
anOrder[x].setValues(char customerName[20], int orderQuantity);
for(x = 0; x< ORDERS; ++x)
{
summary = yearEndTotal(summary,anOrder[x]);
}
summary.displayValues();
getch();
}
The bolded code near the bottom gives me the following errors:
C2059: Syntax error: ')'
C2144: Syntax errror: 'char' should be preceeded by ')'
(although it looks to me like it is?)
C2660: 'Order::setValues': function does not take 0 arguements
Intellisense: too few arguements in function call
Intellisense: type name is not allowed
You're declaring two variables while calling a function. You can't do that.
If you moved declarations of customerName and orderQuantity, there would be another problem. orderQuantity would not get any input since setValues only has a copy of it and cannot affect the original. This could be solved with passing by reference. Although that's still not good. Order already has members customerName and orderQuantity, so why would you pass anything at all? You need to change setValues to take no arguments.
Well don't that beat all. I just removed all the paramters from setValues() and it worked, though I swear I had them empty before and I got an unresolved externals error.
Oh well, it works now. The code doesn't need to be necessarily the "best" way of doing it, it just needs to work as intended, so I'll leave it as is.