Why do I get invalid function declaration when I compile the code in DevC++ in Windows, but when I compile it in CodeBlocks on Linux it works fine.
#include <iostream>
#include <vector>
using namespace std;
//structure to hold item information
struct item{
string name;
double price;
};
//define sandwich, chips, and drink
struct item sandwich{"Sandwich", 3.00}; **** error is here *****
struct item chips{"Chips", 1.50}; **** error is here *****
struct item drink{"Large Drink", 2.00}; **** error is here *****
vector<item> cart; //vector to hold the items
double total = 0.0; //total
const double tax = 0.0825; //tax
//gets item choice from user
char getChoice(){
cout << "Select an item:" << endl;
cout << "S: Sandwich. $3.00" << endl;
cout << "C: Chips. $1.50" << endl;
cout << "D: Drink. $2.00" << endl;
cout << "X: Cancel. Start over" << endl;
cout << "T: Total" << endl;
char choice;
cin >> choice;
return choice;
}
//displays current items in cart and total
void displayCart(){
cout << "\nCart:" << endl;
for(unsigned int i=0; i<cart.size(); i++){
cout << cart.at(i).name << ". $" << cart.at(i).price << endl;
}
cout << "Total: $" << total << endl << endl;
}
//adds item to the cart
void addItem(struct item bought){
cart.push_back(bought);
total += bought.price;
displayCart();
}
//displays the receipt, items, prices, subtotal, taxes, and total
void displayReceipt(){
cout << "\nReceipt:" << endl;
cout << "Items: " << cart.size() << endl;
for(unsigned int i=0; i<cart.size(); i++){
cout << (i+1) << ". " << cart.at(i).name << ". $" << cart.at(i).price << endl;
}
cout << "----------------------------" << endl;
cout << "Subtotal: $" << total << endl;
double taxes = total*tax;
cout << "Tax: $" << taxes << endl;
cout << "Total: $" << (total + taxes) << endl;
}
int main(){
//sentinel to stop the loop
bool stop = false;
char choice;
while (stop == false ){
choice = getChoice();
//add sandwich
if( choice == 's' || choice == 'S' ){
addItem(sandwich);
}
//add chips
else if( choice == 'c' || choice == 'C' ){
addItem(chips);
}
//add drink
else if( choice == 'd' || choice == 'D' ){
addItem(drink);
}
//remove everything from cart
else if( choice == 'x' || choice == 'X' ){
cart.clear();
total = 0.0;
cout << "\n***** Transcation Canceled *****\n" << endl;
}
//calcualte total
else if( choice == 't' || choice == 'T' ){
displayReceipt();
stop = true;
}
//or wront item picked
else{
cout << choice << " is not a valid choice. Try again\n" << endl;
}
}//end while loop
return 0;
//end of program
}