| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
||||||||
|
||||||||
|
Please help me with my project
Hi, I'm currently taking an introduction to C++ class and I'm working on a project. What my project is about is that I'm taking food and drink orders and then it would display it has a receipt and the foods and drinks they've order and displaying the total. I'm having some difficulty finishing it and I'm wondering if someone can help me. One of the problem I'm having is that when it displays the receipt and shows the food and drinks that they've order, it is not showing in the correct order. Also at the beginning of the program when it ask "How many people will be eating" and if you put '3'. then when it is time to order from the menu it will only allow me to from items 3 and under. if i choose 4 and 5 then it will pop up and error message and then terminates the program.
This is my source code and thank you for your time. Also I'm not sure if this is how I'm suppose to post the source code. #include <iostream> #include <fstream> #include <vector> #include <string> #include <iomanip> using namespace std; int main() { const int NUM = 5; string foodName[] = { "Steak ", "Chicken ", "Pasta ", "Lasagna ", "Hamburger "}; // types of food available. Just an example double foodPrice[] = {15.99, 17.95, 11.98, 8.82, 12.99}; // price of food string bevName[] = { "Water ", "Soda ", "Beer ", "Wine ", "Smoothie" }; // types of drinks available. Just an example double bevPrice[] = {00.00, 1.50, 2.25, 5.25, 2.85}; // price of drinks int numPeople, // Number of people index, // loop counter list = 1, // Menu number list starting at 1 order, // user's order choice drinkList = 1; // Menu number for drink list starting at 1 double totalFood = 0.0; // accumulator for food double totalBev = 0.0; // accumulator for drinks // vector <double> foodBill(numPeople); // Holds the order number // Determine how many people are going to be eating cout << "How many people are going to be eating with you today? "; cin >> numPeople; vector <double> foodBillPrice(numPeople); // This needed to be after numPeople is initialized vector <string> foodBillName(numPeople); vector <double> bevBillPrice(numPeople); // This needed to be after numPeople is initialized vector <string> bevBillName(numPeople); cout << fixed << setprecision(2) << showpoint; // Display Menu for food. cout << "\nWhat would you like to order today?" << endl; for (int count = 0; count < NUM; count++) { cout << list << ". " << foodName[count] << "\t" << "$ " << foodPrice[count] << endl; list++; } cout << endl; //ifstream dataIn; //dataIn.open("food.txt"); /* if(!dataIn) cout << "Error opening file.\n"; else { */ // taking the orders for(index = 0; index < numPeople; index++) { cout << "Order for person #" << (index + 1) << ": "; cin >> order; foodBillPrice[order-1] = foodPrice[order - 1]; foodBillName[order-1] = foodName[order - 1]; } cout << endl; // Menu for drinks. cout << "What drinks would you like to order today?" << endl; for (int count = 0; count < NUM; count++) { cout << drinkList << ". " << bevName[count] << "\t" << "$ " << bevPrice[count] << endl; drinkList++; } cout << endl; // taking drinks orders for(index = 0; index < numPeople; index++) { cout << "Order for person #" << (index + 1) << ": "; cin >> order; bevBillPrice[order-1] = bevPrice[order - 1]; bevBillName[order-1] = bevName[order - 1]; } // Calculating total food for(index = 0; index < numPeople; index++) { totalFood += foodBillPrice[index]; } cout << endl; // Calculating total drink cost for(index = 0; index < numPeople; index++) { totalBev += bevBillPrice[index]; } Code:
cout << endl; Code:
// Adding sales tax to total double salesTax = 7.75, totalFoodAndBev = totalFood + totalBev, totalTax = totalFoodAndBev * (salesTax / 100), totalWithTax = (totalTax + totalFoodAndBev); // Displaying sub total before tax cout << "\nSub Total" << "\t" << "$ " << totalFoodAndBev << endl; // Display sales tax on receipt cout << "Tax(7.75%)" << "\t" << "$ " << totalTax << endl; cout << "\t\t" << "----------" << endl << "Total" << "\t\t" << "$ " << totalWithTax << endl; // } return 0; } Edit *** I've highlighted the part where i know where the problem is at but i dont know how to fix it. |
|
#2
|
|||
|
|||
|
also this is only part of the program and my group-mate has the rest. thats y the '//' is in the ifstream.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Please help me with my project |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|