I need immediate help here. Please help me! :)
I just can't figure out why my program is crashing while executing it.
The compiling of the program is fine. (no syntax errors)
I used Dev C++ 4.9 for this version.
#include <iostream> #include <conio.h> #include <iomanip> #include <string> using namespace std; const double t = 0.20; // tax struct menuItemtype { string fm; // food menu double fp; // food price double ad; // amount due }; menuItemtype getData(); void showMenu(); int main() { showMenu(); getche(); return 0; } menuItemtype getData() { menuItemtype menuList[8] = { {"Plain Egg", 1.45}, {"Bacon and Egg", 2.45}, {"Muffin", 0.99}, {"French Toast", 1.99}, {"Fruit Basket", 2.49}, {"Cereal", 0.69}, {"Coffee", 0.50}, {"Tea", 0.75}}; return menuList[8]; } void showMenu() { menuItemtype m[8]; // menu int i; m[8] = getData(); for(i = 0; i < 8; i++) { cout << m[i].fm << " " << m[i].fp << endl; } }
Anyway, it is not actually a complete work. I'm still going to add somethings in here..
I just want to know why it is crashing.
If you are going to use Visual Studio, here's a 2nd version of my work.
#include "iostream" #include "stdfax.h" #include "iomanip" #include "string" using namespace std; const double t = 0.20; // tax struct menuItemtype { string fm; // food menu double fp; // food price double ad; // amount due }; menuItemtype getData(); void showMenu(); int main() { showMenu(); // displays food menu and food prices system("pause"); /* I am going to change this after I'm done with knowing why my program is crashing */ return 0; } menuItemtype getData() { menuItemtype menuList[8] = { {"Plain Egg", 1.45}, {"Bacon and Egg", 2.45}, {"Muffin", 0.99}, {"French Toast", 1.99}, {"Fruit Basket", 2.49}, {"Cereal", 0.69}, {"Coffee", 0.50}, {"Tea", 0.75}}; return menuList[8]; } void showMenu() { menuItemtype m[8]; // menu int i; m[8] = getData(); for(i = 0; i < 8; i++) { cout << m[i].fm << " " << m[i].fp << endl; } } --------
Care to help me out?