MetalTabs.com - your source for Metal tabs
Home Forum FAQ Contact Us Link to Us


Go Back   MetalTabs.com Forum > MetalTabs.com > Chit Chat


 
 
Old 2007-02-23, 02:57
mrs. malicious's Avatar
mrs. malicious
Senior Metalhead
 
Join Date: Aug 2006
Location: tn
Posts: 300
C++

i know i'll get yelled at for this thread, but i need help asap. my csci class is absorbing my spare time lately. if anyone here knows how to fix this and posts before 11:45 cst, my appreciation will be far from ephemeral. i'll post my entire program after i copy a post i made on the class's discussion board that explains my problem. no one there has answered me.....c'mon i know you guys are nice! please! i beseech you all!! :<

here're my problems:

"Okay, I understand how the functions work. My program is running successfully except for a few small glitches. First, the three lines with the meals and pricing information on them aren't outputting the way I want. It puts the information from the function first, like this:

Meal Quantity Cost Discount Cost After Discount
165.00 16.50 148.50Breakfast 30 nan
266.00 39.90 226.10Lunch 28 nan
412.50 49.50 363.00Dinner 25 nan

(In my program it's aligned much better than in this post.) I can't figure out how to get the function to return its information at the end of the line. "Breakfast" is supposed to be the first word on the line. Also, I have no idea where that "nan" is coming from. This is what my code looks like for the "Breakfast" line:

cout < < "Breakfast " < < brkfst_qty < < " " < < meal_discount(brkfst_qty, brkfst_cost_each, brkfst_discount_percent, brkfst_order_over) < < endl;

How can I get this to display at the end of the line?

My other problem is with displaying the subtotal. Doubles declared in the function are only usable in the function itself, right? So how do I display something like "subtotal = cost_1 + cost_2 + cost_3;" if the costs are displayed by way of the function and I can't use the identifier that I used in the function? I hope I'm making sense, and thanks in advance for any help."

you'll notice i have a one listed as the subtotal.....that's just there because i had to put something.

Code:
//Caitlin Schipper //Program to calculate meal discounts for the "Schipper Catering Service" //1010-W1 PASS5 #include<iostream> #include<iomanip> using namespace std; double meal_discount(int qty, double cost_each, double discount_percent, int order_over); //Return the meal prices after discount for each type of meal. int main () { int brkfst_qty, lunch_qty, dinner_qty; double subtotal, sales_tax, total_due; const double tax = 0.10; const double brkfst_cost_each = 5.50; const double lunch_cost_each = 9.50; const double dinner_cost_each = 16.50; const double brkfst_discount_percent = 0.10; const double lunch_discount_percent = 0.15; const double dinner_discount_percent = 0.12; const int brkfst_order_over = 10; const int lunch_order_over = 15; const int dinner_order_over = 8; cout<<setiosflags(ios::fixed|ios::showpoint)<<setprecision(2); cout<<"Welcome to the Schipper Catering Service.\n"<<endl; cout<<"Enter the number of breakfasts ordered: "; cin>>brkfst_qty; cout<<"Enter the number of lunches ordered: "; cin>>lunch_qty; cout<<"Enter the number of dinners ordered: "; cin>>dinner_qty; cout<<endl<<endl; cout<<" Schipper Catering Service "<<endl; cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; cout<<"Meal Quantity Cost Discount Cost After Discount"<<endl; cout<<"Breakfast "<<brkfst_qty<<" "<<meal_discount(brkfst_qty, brkfst_cost_each, brkfst_discount_percent, brkfst_order_over)<<endl; cout<<"Lunch "<<lunch_qty<<" "<<meal_discount(lunch_qty, lunch_cost_each, lunch_discount_percent, lunch_order_over)<<endl; cout<<"Dinner "<<dinner_qty<<" "<<meal_discount(dinner_qty, dinner_cost_each, dinner_discount_percent, dinner_order_over)<<endl; cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; subtotal = 1; sales_tax = subtotal * tax; total_due = subtotal + sales_tax; cout<<"Subtotal "<<subtotal<<endl; cout<<"Sales Tax "<<sales_tax<<endl; cout<<"Total Due "<<total_due<<endl; return 0; } double meal_discount(int qty, double cost_each, double discount_percent, int order_over) { double cost, discount, cost_after_discount; if (qty > order_over) { cost = qty * cost_each; discount = cost * discount_percent; cost_after_discount = cost - discount; cout<<cost<<" "<<discount<<" "<<cost_after_discount; } else { cost = qty * cost_each; discount = 0.00; cost_after_discount = cost; cout<<cost<<" "<<discount<<" "<<cost_after_discount; } }


help me and i will you eternally.
__________________
-/caitlin\-

im in ur srvr
eatin ur dataz

Quote:
Originally Posted by CannibalXampire
doom metal tries to invoke the feeling of being a really fat guy stuck in the trash compactor from Star Wars IV
 
Old 2007-02-23, 03:09
tmfreak's Avatar
tmfreak
Slayer of dumb cunts
 
Join Date: Sep 2005
Location: Virginia Tech, Blacksburg, va
Posts: 3,622
i could most definitely help you on this. I help proaz what seems like daily with C++ and programming. Problem is i would need to spend sometime looking at your code and trouble shooting it myself. Best thing for you to do is debug it. Debuging fucking rocks. Being able to go through the execution of your program and see how each individual step is performing. Alot of times you can save alot of heartache and trouble by using it.
__________________
Quote:
Originally Posted by Darko
...Its very annoying to keep having to hear some socially-disabled teen come on these boards talking about all the drugs he's started doing so that he can maybe grasp onto some kind of positive response so he feels better about himself and what he's doing.
About requiem. Aint it the truth...
 
Old 2007-02-23, 03:23
mrs. malicious's Avatar
mrs. malicious
Senior Metalhead
 
Join Date: Aug 2006
Location: tn
Posts: 300
Quote:
Originally Posted by tmfreak
i could most definitely help you on this. I help proaz what seems like daily with C++ and programming. Problem is i would need to spend sometime looking at your code and trouble shooting it myself. Best thing for you to do is debug it. Debuging fucking rocks. Being able to go through the execution of your program and see how each individual step is performing. Alot of times you can save alot of heartache and trouble by using it.


yeah pr0az's helping me on aim.....i already debugged it and it runs fine, and my function returns all the right prices.....i just have to manipulate the formatting for those three lines of output..and figure out how the hell to write up the subtotal. if you can help too, please do,
__________________
-/caitlin\-

im in ur srvr
eatin ur dataz

Quote:
Originally Posted by CannibalXampire
doom metal tries to invoke the feeling of being a really fat guy stuck in the trash compactor from Star Wars IV
 
Old 2007-02-23, 03:26
Requiem
Post-whore
 
Join Date: Sep 2005
Location: terra firma
Posts: 6,940
c++ looks like gibberish to me now, but next year it will be a different story.

a teacher at my local high school is creating a new class to teach students c++ to design a 3d game and publish it on a web page
 
Old 2007-02-23, 04:40
mrs. malicious's Avatar
mrs. malicious
Senior Metalhead
 
Join Date: Aug 2006
Location: tn
Posts: 300
PR0AZ SAVES THE DAY
__________________
-/caitlin\-

im in ur srvr
eatin ur dataz

Quote:
Originally Posted by CannibalXampire
doom metal tries to invoke the feeling of being a really fat guy stuck in the trash compactor from Star Wars IV
 
Old 2007-02-23, 10:58
tmfreak's Avatar
tmfreak
Slayer of dumb cunts
 
Join Date: Sep 2005
Location: Virginia Tech, Blacksburg, va
Posts: 3,622
Quote:
Originally Posted by mrs. malicious
PR0AZ SAVES THE DAY


I've taught him well..
__________________
Quote:
Originally Posted by Darko
...Its very annoying to keep having to hear some socially-disabled teen come on these boards talking about all the drugs he's started doing so that he can maybe grasp onto some kind of positive response so he feels better about himself and what he's doing.
About requiem. Aint it the truth...
 
Old 2007-02-24, 04:22
mrs. malicious's Avatar
mrs. malicious
Senior Metalhead
 
Join Date: Aug 2006
Location: tn
Posts: 300
Quote:
Originally Posted by tmfreak
I've taught him well..


tch don't take all the credit.....i might come after you next time!
__________________
-/caitlin\-

im in ur srvr
eatin ur dataz

Quote:
Originally Posted by CannibalXampire
doom metal tries to invoke the feeling of being a really fat guy stuck in the trash compactor from Star Wars IV
 
Old 2007-03-22, 22:52
Requiem
Post-whore
 
Join Date: Sep 2005
Location: terra firma
Posts: 6,940
i have a small problem im not sure if its in the syntax or what but here is my source code


Quote:
// Ex2_01.CPP
// A Simple Example of a Program
#include <iostream>

using namespace std;

int main()
{
int apples, oranges;
int fruit;

apples = 5; oranges = 6;
fruit = apples + oranges;

cout << endl;
cout << "Oranges are not the only fruit..." << endl
<< "- and we have " << fruit << "fruits in all";
cout << endl;

return 0;

}

ok dont criticize at the how simple this problem. okej, this is what the out come is

"Oranges are not the only fruit...
- and we have 11fruits in all."

But the correct way should be " 11 fruits" not "11fruits"

can anyone help?
 
Old 2007-03-22, 23:09
sqol's Avatar
sqol
Post-whore
 
Join Date: Mar 2005
Location: London, UK
Posts: 1,841
If you just put a space in there, so that line reads:
Code:
<< "- and we have " << fruit << " fruits in all";


Simple
__________________

The Freedom of Chaos
The Secret of The Secret
The Truth of The Truth

Quote:
Originally Posted by Undone
moonraven?....more like ass raven
 
Old 2007-03-22, 23:16
Requiem
Post-whore
 
Join Date: Sep 2005
Location: terra firma
Posts: 6,940
THanks! I'm still getting use to the formatting/
 
Old 2007-03-23, 00:48
Pr0az's Avatar
Pr0az
Post-whore
 
Join Date: Oct 2006
Posts: 1,924
int apples, oranges;
int fruit;

apples = 5; oranges = 6;


as for that req you can set variables right time you declare them for example

int apples = 5, oranges = 6;

is the same as above with less coding involed...
__________________
“Remember to live, eat, sleep and breathe music for the mind, play from your heart and never be swayed by the current trends.” ~Rusty Cooley
 
Old 2007-03-23, 01:02
Requiem
Post-whore
 
Join Date: Sep 2005
Location: terra firma
Posts: 6,940
thanks, i'll take any advice that more experienced programmers want to offer

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 Off
HTML code is Off



Top

========

Contact Us | Privacy Policy | Disclaimer
Copyright © 2001-2014 MetalTabs.com. All Rights Reserved.
Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.