C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Iron Speed
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old May 9th, 2008, 12:49 AM
DrDrew DrDrew is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 2 DrDrew User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 24 sec
Reputation Power: 0
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:
Original - Code
    // Displaying food order and prices         for(index = 0; index < numPeople; index++)         {             cout << foodBillName[/*order-1*/index] << "\t" << "$ " << foodBillPrice[/*order-1*/index] << endl;         }

cout << endl;


Code:
Original - Code
    // Displaying drink order and prices         for(index = 0; index < numPeople; index++)         {             cout << bevBillName[/*order-1*/index] << "\t" << "$ " << bevBillPrice[/*order-1*/index] << endl;         }


// 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.

Reply With Quote
  #2  
Old May 9th, 2008, 12:51 AM
DrDrew DrDrew is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 2 DrDrew User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 24 sec
Reputation Power: 0
also this is only part of the program and my group-mate has the rest. thats y the '//' is in the ifstream.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Please help me with my project


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five &quot;checkpoints&quot; for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway