Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Keep getting error message from codeblocks compiler \"Line 108 Error: \'strcpy\'

ID: 3682643 • Letter: K

Question

Keep getting error message from codeblocks compiler "Line 108 Error: 'strcpy' was not declared in this scope"

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

struct menuItemType
{
   string menuItem[20];
   double menuPrice;
};

void getData(menuItemType menuList[8]);
void showMenu(menuItemType menuList[8],menuItemType orderList[], int orderCounter, int selection);
void printCheck(menuItemType menuList[8],int orderCounter, const double TAX);

    const int MAX = 8;
    const double TAX = 1.05;

     menuItemType menuList[8];
     menuItemType orderList[MAX];


int main()
{
    int orderCounter = 0;
    int selection = ' ';

       getData(menuList);
       showMenu(menuList, orderList, orderCounter, selection);
       printCheck(orderList, orderCounter, TAX);


   return 0;
}

void getData(menuItemType menuList[8])
{
   strcpy(menuList[0].menuItem,"Plain Egg");
   menuList[0].menuPrice = 1.45;
   strcpy(menuList[1].menuItem,"Bacon and Egg");
   menuList[1].menuPrice = 2.45;
   strcpy(menuList[2].menuItem,"Muffin");
   menuList[2].menuPrice = 0.99;
   strcpy(menuList[3].menuItem,"French Toast");
   menuList[3].menuPrice = 1.99;
   strcpy(menuList[4].menuItem,"Fruit Basket");
   menuList[4].menuPrice = 2.49;
   strcpy(menuList[5].menuItem,"Cereal");
   menuList[5].menuPrice = 0.69;
   strcpy(menuList[6].menuItem,"Coffee");
   menuList[6].menuPrice = 0.50;
   strcpy(menuList[7].menuItem,"Tea");
   menuList[7].menuPrice = 0.75;
}

void showMenu(menuItemType menuList[8],menuItemType orderList[], int orderCounter, int selection)
{
   cout << "1 - Plain Egg" << setw(14) << "$1.45" << endl;
   cout << "2 - Bacon and Egg" << setw(10) << "$2.45" << endl;
   cout << "3 - Muffin" << setw(17) << "$0.99" << endl;
   cout << "4 - French Toast" << setw(11) << "$1.99" << endl;
   cout << "5 - Fruit Basket" << setw(11) << "$2.49" << endl;
   cout << "6 - Cereal" << setw(17) << "$0.69" << endl;
   cout << "7 - Coffee" << setw(17) << "$0.50" << endl;
   cout << "8 - Tea" << setw(21) << "$0.75 " << endl;
    do{
   cout << "Enter the number of your selections until you are finished with your order." << endl;
   cout << "Enter 9 when you are done ordering." << endl;
   cin >> selection;

    switch(selection){
           case 9:
               break;
           case 1:
               cout << menuList[0].menuItem << setw(14) << "$1.45";
               break;
           case 2:
               cout << menuList[1].menuItem << setw(10) << "$2.45";
               break;
           case 3:
               cout << menuList[2].menuItem << setw(17) << "$0.99";
               break;
           case 4:
               cout << menuList[3].menuItem << setw(11) << "$1.99";
               break;
           case 5:
               cout << menuList[4].menuItem << setw(11) << "$2.49";
               break;
           case 6:
               cout << menuList[5].menuItem << setw(17) << "$0.69";
               break;
           case 7:
               cout << menuList[6].menuItem << setw(17) << "$0.50";
               break;
           case 8:
               cout << menuList[7].menuItem << setw(20) << "$0.75";
               break;
           default:
               cout << "Selection's must be between 1 and 9 ";
               break;
       }
   }
   while (selection !=9);
    if ((selection >=0)&& (selection <= MAX))
    {
        strcpy(orderList[orderCounter].menuItem,menuList[selection-1].menuItem);
        orderList[orderCounter].menuPrice = menuList[selection-1].menuPrice;
        orderCounter++;
    }
    else if (selection == 9)
   cout << "Exit" << endl;
   else
   cout << "Invalid Entry" << endl;
}
    void printCheck(menuItemType orderList[],int orderCounter, const double TAX)
    {
   cout << "Welcome to Johnny's" << endl;
   for (orderCounter = 0,orderCounter < MAX, orderCounter++)
    cout << orderList[orderCounter].menuItem << " " << orderList[orderCounter].menuPrice <<endl;
    cout << "Tax" << setw(10)<< TAX << endl;
    cout << " Amount Due" << setw(10) << endl;
}

Explanation / Answer

I have fixed all your compilation errors:

0. You were getting strcpy undeclared because you haven't included cstring file. Like

#include <cstring>

1. When using string (instead of char array) in structure you are declaring an array of string objects not a single string. To declare an array of 20 characters you should write

char menuItem[20];

1. When using string (object) you don't need to use strcpy to copy a string into it. You can directly assign it. Like

menuItem = "Plain eggs"

updated your code which compiles successfully:

#include <iostream>
#include <string>
#include <iomanip>
#include <cstring>
using namespace std;

struct menuItemType {
string menuItem;
double menuPrice;
};

const int MAX = 8;
const double TAX = 1.05;
menuItemType menuList[8];
menuItemType orderList[MAX];

void getData(menuItemType[]);

void showMenu(menuItemType[], menuItemType[], int, int);

void printCheck(menuItemType menuList[],int orderCounter, const double TAX);


int main() {
int orderCounter = 0;
int selection = ' ';
getData(menuList);
showMenu(menuList, orderList, orderCounter, selection);
printCheck(orderList, orderCounter, TAX);
return 0;
}

void getData(menuItemType menuList[]) {
menuList[0].menuItem = "Plain Egg";
menuList[0].menuPrice = 1.45;

menuList[1].menuItem ="Bacon and Egg";
menuList[1].menuPrice = 2.45;

menuList[2].menuItem = "Muffin";
menuList[2].menuPrice = 0.99;

menuList[3].menuItem ="French Toast";
menuList[3].menuPrice = 1.99;

menuList[4].menuItem = "Fruit Basket";
menuList[4].menuPrice = 2.49;

menuList[5].menuItem = "Cereal";
menuList[5].menuPrice = 0.69;

menuList[6].menuItem = "Coffee";
menuList[6].menuPrice = 0.50;

menuList[7].menuItem = "Tea";
menuList[7].menuPrice = 0.75;
}

void showMenu(menuItemType menuList[8],menuItemType orderList[], int orderCounter, int selection) {
cout << "1 - Plain Egg" << setw(14) << "$1.45" << endl;
cout << "2 - Bacon and Egg" << setw(10) << "$2.45" << endl;
cout << "3 - Muffin" << setw(17) << "$0.99" << endl;
cout << "4 - French Toast" << setw(11) << "$1.99" << endl;
cout << "5 - Fruit Basket" << setw(11) << "$2.49" << endl;
cout << "6 - Cereal" << setw(17) << "$0.69" << endl;
cout << "7 - Coffee" << setw(17) << "$0.50" << endl;
cout << "8 - Tea" << setw(21) << "$0.75 " << endl;
do {
cout << "Enter the number of your selections until you are finished with your order." << endl;
cout << "Enter 9 when you are done ordering." << endl;
cin >> selection;
switch(selection){
case 9:
break;
case 1:
cout << menuList[0].menuItem << setw(14) << "$1.45 ";
break;
case 2:
cout << menuList[1].menuItem << setw(10) << "$2.45 ";
break;
case 3:
cout << menuList[2].menuItem << setw(17) << "$0.99 ";
break;
case 4:
cout << menuList[3].menuItem << setw(11) << "$1.99 ";
break;
case 5:
cout << menuList[4].menuItem << setw(11) << "$2.49 ";
break;
case 6:
cout << menuList[5].menuItem << setw(17) << "$0.69 ";
break;
case 7:
cout << menuList[6].menuItem << setw(17) << "$0.50 ";
break;
case 8:
cout << menuList[7].menuItem << setw(20) << "$0.75 ";
break;
default:
cout << "Selection's must be between 1 and 9 ";
break;
}
} while (selection !=9);

if ((selection >=0)&& (selection <= MAX)) {
orderList[orderCounter].menuItem = menuList[selection-1].menuItem;
orderList[orderCounter].menuPrice = menuList[selection-1].menuPrice;
orderCounter++;
} else if (selection == 9) {
cout << "Exit" << endl;
} else {
cout << "Invalid Entry" << endl;
}
}

void printCheck(menuItemType orderList[],int orderCounter, const double TAX) {
cout << "Welcome to Johnny's" << endl;

for (orderCounter = 0; orderCounter < MAX; orderCounter++)
cout << orderList[orderCounter].menuItem << " " << orderList[orderCounter].menuPrice <<endl;

cout << "Tax" << setw(10)<< TAX << endl;
cout << " Amount Due" << setw(10) << endl;
}