Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am trying to figure out why i am getting an array subscript error in dev c++. Here is my code, can I get help

I am trying to figure out why i am getting an array subscript error in dev c++. Here is my code, can I get help with this?

#include #include #include

using namespace std;

struct menuItemType { string menuItem; double menuPrice; };

//Function void getData(menuItemType[], int); void showMenu(menuItemType[], int); int makeOrder(int [], int); void printCheck(menuItemType[], int, int [], int);

int main() { menuItemType breakfastList[8]; int orderList[8]; int orderListSize = 0; getData(breakfastList, 8); showMenu(breakfastList, 8); orderListSize = makeOrder(orderList, 8); printCheck(breakfastList, 8, orderList, orderListSize); return 0; } void getData(menuItemType itemList[], int itemListLen) { ifstream inData; char ch; inData.open("ch9_Ex4Data.txt"); if(!inData){ cout << "Can not open int file (Error). Program terminates!"; return; } //inData >> itemList[0].menuItem; for (int i = 0; i < itemListLen; i++) { getline(inData, itemList[i].menuItem); inData >> itemList[i].menuPrice; inData.get(ch); } //close inData.close(); }

void showMenu(menuItemType menuItems[], int menuItemsSize){ cout <<"Welcome to Johnny's Restaurant"<> yesNo; while (((yesNo == 'Y'|| (yesNo == 'y'))&&(totalItemNumbers < 8))) { cout << "What item: "; cin >> selection; numList[totalItemNumbers] = selection; totalItemNumbers++; cout << "yes(next) or no(stop): "; cin >> yesNo;

} return totalItemNumbers; } void printCheck(menuItemType[], int Size, int sArr[], int sArrSize){ double total = 0; for (int i = 0; i < sArrSize; i++){ cout << 1[sArr[i]].menuItems <<" "; cout << 1[sArr[i]].menuPrice << endl; total += 1[sArr[i]].menuPrice; }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To Database 2

Authors: Bruce L. Larson

1st Edition

0070232679, 978-0070232679

More Books

Students also viewed these Databases questions

Question

Were they made on a timely basis?

Answered: 1 week ago

Question

Did the decisions need to be made, or had they already been made?

Answered: 1 week ago

Question

When there was controversy, was it clear who had the final say?

Answered: 1 week ago