Find fields & stores near you!
Find fields and stores
Zipcode
PbNation News
PbNation News
Community Focus
Community Focus

Closed Thread
 
Thread Tools
Old 10-14-2008, 11:15 AM #1
CyanidePoison
 
 
CyanidePoison's Avatar
 
Join Date: Dec 2006
Location: La Porte, IN
Official Tech. Programming Thread

I like programming.

You like programming.

Discuss.


RESOURCES:
Python
Dive Into Python- free online book that is basically the best resource for learning Python.

That's all I've got, considering Python is the only language I regularly use.


Please use
Code:
code
tags!
-----------------------------------------------------------------------------------------------------------------------------------



/*
Here we discuss everything from A+ to Z.


http://en.wikipedia.org/wiki/Programming_language
Quote:
A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer. Programming languages can be used to create programs that specify the behavior of a machine, to express algorithms precisely, or as a mode of human communication.
http://en.wikipedia.org/wiki/List_of...ming_languages


C++
http://msdn.microsoft.com/en-us/beginner/cc305129.aspx
http://www.cplusplus.com/doc/tutorial/
http://tinyurl.com/mwj8p3

Python:
http://wiki.python.org/moin/BeginnersGuide
http://wiki.python.org/moin/FrontPage

Visual Basic:
http://en.wikipedia.org/wiki/Visual_Basic

Java:
http://www.java.com/en/
http://en.wikipedia.org/wiki/Java_(programming_language)
http://www.javacoffeebreak.com/
http://java.sun.com/docs/books/tutorial/
__________________
ST:T: We have subforums with more posts and threads than you.

Last edited by CyanidePoison : 09-26-2009 at 09:14 AM.
CyanidePoison is offline  
Old Sponsored Links Remove Advertisement
Advertisement
Old 10-14-2008, 11:20 AM #2
Jocasta (Banned)
Captain Strobe
 
Join Date: Mar 2007
Location: KO's bushes
h0w d0 i hax my naybars intarnetz
Jocasta is offline  
Old 10-14-2008, 11:23 AM #3
CyanidePoison
 
 
CyanidePoison's Avatar
 
Join Date: Dec 2006
Location: La Porte, IN
You either crack the key through a flaw (IE WEP), or brute force (IE short WPA).
__________________
ST:T: We have subforums with more posts and threads than you.
CyanidePoison is offline  
Old 10-14-2008, 11:26 AM #4
Jocasta (Banned)
Captain Strobe
 
Join Date: Mar 2007
Location: KO's bushes
k i has makbuk and mitee moses linx me 2 sum hax kthx
Jocasta is offline  
Old 10-14-2008, 11:34 AM #5
CyanidePoison
 
 
CyanidePoison's Avatar
 
Join Date: Dec 2006
Location: La Porte, IN
http://hacks.this.link:24234/uber/ha...r-de-duper.zip

Ok enough funny business.
__________________
ST:T: We have subforums with more posts and threads than you.
CyanidePoison is offline  
Old 10-14-2008, 11:35 AM #6
Jocasta (Banned)
Captain Strobe
 
Join Date: Mar 2007
Location: KO's bushes
Sorry sir. Posting here in lieu of doing homework.
Jocasta is offline  
Old 10-14-2008, 11:37 AM #7
kif
 
 
Join Date: Jun 2004
Location: Panama City Beach
kif is a Supporting Member
 has been a member for 10 years
For my C++ class, we need to make a "Tip Table" with a universal constant for the tip percentage. It needs to calculate the tip and total bill for tabs from $5 to $100 in $5 increments. I got it all coded out, but I just need to figure out how to get it to line up on the table.

This is the output I get:


Basically, I need to figure out how to get all the dollar signs lined up in each column.

This is my code:
Code:
#include <iostream> using namespace std; const double TIP_PERCENT = 0.18; double tip(double ticket); // Calculates the tip amount double total(double ticket); // Calculates the total price, including tip int main() { cout << "***************************************************\n"; cout << "* Welcome to Patrick's Tip Calculating Program! *\n"; cout << "***************************************************\n"; double bill = 5.00; cout << " Bill Tip Total\n"; cout << "====== ===== =======\n"; while (bill <= 100.00) { cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); cout << "$" << bill << " $" << tip(bill) << " $" << total(bill) << endl; bill += 5.00; } cout << "Press ENTER to exit..."; cin.get(); return 0; } double tip(double ticket) { double tip = (ticket * TIP_PERCENT); return tip; } double total(double ticket) { double total = ticket + (ticket * TIP_PERCENT); return total; }
Does anybody have a suggestion for what I should look up to find out how to get the spacing right?

Also, I know my code probably isn't stylistically correct, but I'm not extremely worried about that at this moment. However, if you have any suggestions and/or recommendations for improving that, I'm open to those also.

Thanks guys.
kif is offline  
Old 10-14-2008, 11:39 AM #8
LiQuId StEeL
 
 
LiQuId StEeL's Avatar
 
Join Date: Jul 2004
Location: Miami University
I know in java there is a printf output type, which let you set, essentially, column widths for various outputs.

I don't know C++, but I would imagine there is something similar.
__________________
LiQuId StEeL is offline  
Old 10-14-2008, 11:47 AM #9
CyanidePoison
 
 
CyanidePoison's Avatar
 
Join Date: Dec 2006
Location: La Porte, IN
You could use tabs in spots instead of just putting in whitespace.
__________________
ST:T: We have subforums with more posts and threads than you.
CyanidePoison is offline  
Old 10-14-2008, 11:52 AM #10
CyanidePoison
 
 
CyanidePoison's Avatar
 
Join Date: Dec 2006
Location: La Porte, IN
Code:
while (bill <= 100.00) { cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); cout << "$" << bill << "\t$" << tip(bill) << "\t$" << total(bill) <<endl; bill += 5.00; }
On my terminal it outputs as:
Code:
*************************************************** * Welcome to Patrick's Tip Calculating Program! * *************************************************** Bill Tip Total ====== ===== ======= $5.00 $0.90 $5.90 $10.00 $1.80 $11.80 $15.00 $2.70 $17.70 $20.00 $3.60 $23.60 $25.00 $4.50 $29.50 $30.00 $5.40 $35.40 $35.00 $6.30 $41.30 $40.00 $7.20 $47.20 $45.00 $8.10 $53.10 $50.00 $9.00 $59.00 $55.00 $9.90 $64.90 $60.00 $10.80 $70.80 $65.00 $11.70 $76.70 $70.00 $12.60 $82.60 $75.00 $13.50 $88.50 $80.00 $14.40 $94.40 $85.00 $15.30 $100.30 $90.00 $16.20 $106.20 $95.00 $17.10 $112.10 $100.00 $18.00 $118.00 Press ENTER to exit...
There ya go. Add more tabs in spots to make it look nicer if you want. That will work for all values up to 1000, then you'll have to change some stuff up, but that's no big deal.
__________________
ST:T: We have subforums with more posts and threads than you.

Last edited by CyanidePoison : 10-14-2008 at 12:01 PM.
CyanidePoison is offline  
Old 10-14-2008, 12:14 PM #11
zellthemedic
GRAAAAAAA
 
zellthemedic's Avatar
 
Join Date: Apr 2007
Location: NAS Oceana, VA
zellthemedic helped look for balloons
zellthemedic is playing at Living Legends III
zellthemedic owns a Planet Eclipse Ego
zellthemedic is for the Gunfight
zellthemedic has achieved Level 3 in PbNation Pursuit
We had to do a breakfast/lunch/dinner price calculation for a catering service. We did bulk discounts and such, then we added tax at the end. I've got the code around hurr somewhere.

Code:
//Phillip Alter //CompSci 1010 //Written on September 30th, 2008 /* This program is used to calculate the price of meals after discounts if enough meals were ordered to get a discount, then calculates the total with tax. */ #include<iostream> #include<iomanip> using namespace std; double calcDiscount (int,double,double,int); const double BFCE=5.50, BFDP=.10, LCE=9.50, LDP=.15, DCE=16.50, DDP=.12, tax=1.1, sTax=.1; const int BFOMT=10, LOMT=15, DOMT=8; int main() { int BFQ,LQ,DQ; double BFD,LD, DD, BCBD, LCBD, DCBD, BFBT, LBT, DBT, total, subtotal, salesTax; cout<<"Enter number of breakfasts"<<endl; cin>>BFQ; cout<<"Now enter the number of lunches"<<endl; cin>>LQ; cout<<"Finally, enter the number of dinners"<<endl; cin>>DQ; BFD=calcDiscount(BFQ, BFCE, BFDP, BFOMT); LD=calcDiscount(LQ, LCE, LDP, LOMT); DD=calcDiscount(DQ, DCE, DDP, DOMT); //ZEE MATH BCBD=BFQ*BFCE; LCBD=LQ*LCE; DCBD=DQ*DCE; BFBT=BCBD-BFD; LBT=LCBD-LD; DBT=DCBD-DD; subtotal=DBT+LBT+BFBT; cout<<"***************************"<<endl; cout<<"BREAKFAST"<<endl; cout<<"***************************"<<endl; cout<<"Amount of breakfasts: "<<BFQ<<endl; cout<<setiosflags(ios::fixed|ios::showpoint)<<"Price before discount: $"<<setprecision(2)<<BCBD<<endl; cout<<setiosflags(ios::fixed|ios::showpoint)<<"Discount: $"<<setprecision(2)<<BFD<<endl; cout<<setiosflags(ios::fixed|ios::showpoint)<<"Total cost before tax: $"<<setprecision(2)<<BFBT<<endl; cout<<"***************************"<<endl; cout<<"LUNCH"<<endl; cout<<"***************************"<<endl; cout<<"Amount of lunches: "<<LQ<<endl; cout<<setiosflags(ios::fixed|ios::showpoint)<<"Price before discount: $"<<setprecision(2)<<LCBD<<endl; cout<<setiosflags(ios::fixed|ios::showpoint)<<"Discount: $"<<setprecision(2)<<LD<<endl; cout<<setiosflags(ios::fixed|ios::showpoint)<<"Total cost before tax: $"<<setprecision(2)<<LBT<<endl; cout<<"***************************"<<endl; cout<<"DINNER"<<endl; cout<<"***************************"<<endl; cout<<"Amount of dinners: "<<DQ<<endl; cout<<setiosflags(ios::fixed|ios::showpoint)<<"Price before discount: $"<<setprecision(2)<<DCBD<<endl; cout<<setiosflags(ios::fixed|ios::showpoint)<<"Discount: $"<<setprecision(2)<<DD<<endl; cout<<setiosflags(ios::fixed|ios::showpoint)<<"Total cost without tax: $"<<setprecision(2)<<DBT<<endl; cout<<"***************************"<<endl; cout<<setiosflags(ios::fixed|ios::showpoint)<<"Subtotal: $"<<setprecision(2)<<subtotal<<endl; cout<<setiosflags(ios::fixed|ios::showpoint)<<"Sales Tax: $"<<setprecision(2)<<salesTax<<endl; cout<<setiosflags(ios::fixed|ios::showpoint)<<"Total: $"<<setprecision(2)<<total<<endl; return 0; } double calcDiscount(int quantity, double costEach, double DiscountPercent, int orderMorethan){ double discountBefore; double costBefore; costBefore=quantity*costEach; if (quantity>=orderMorethan) discountBefore=costBefore*DiscountPercent; else discountBefore=0.0; return discountBefore; }
EDIT: The code looks REALLY FUGLY right there, but in the program it isn't THAT messy.



And the output came out to:

Code:
Enter number of breakfasts 14 Now enter the number of lunches 15 Finally, enter the number of dinners 16 *************************** BREAKFAST *************************** Amount of breakfasts: 14 Price before discount: $77.00 Discount: $7.70 Total cost before tax: $69.30 *************************** LUNCH *************************** Amount of lunches: 15 Price before discount: $142.50 Discount: $21.38 Total cost before tax: $121.12 *************************** DINNER *************************** Amount of dinners: 16 Price before discount: $264.00 Discount: $31.68 Total cost without tax: $232.32 *************************** Subtotal: $422.75 Sales Tax: $42.27 Total: $465.02
__________________
After dark OT:T GDT crew: More RAM than the Himalayas
OT:T:G: We sometimes like gaming, but not really -- but we really like zombies

UNITED STATES NAVY

Last edited by zellthemedic : 10-14-2008 at 12:22 PM.
zellthemedic is offline  
Old 10-14-2008, 12:14 PM #12
kif
 
 
Join Date: Jun 2004
Location: Panama City Beach
kif is a Supporting Member
 has been a member for 10 years
Quote:
Originally Posted by CyanidePoison View Post
Code:
while (bill <= 100.00) { cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); cout << "$" << bill << "\t$" << tip(bill) << "\t$" << total(bill) <<endl; bill += 5.00; }
On my terminal it outputs as:
Code:
*************************************************** * Welcome to Patrick's Tip Calculating Program! * *************************************************** Bill Tip Total ====== ===== ======= $5.00 $0.90 $5.90 $10.00 $1.80 $11.80 $15.00 $2.70 $17.70 $20.00 $3.60 $23.60 $25.00 $4.50 $29.50 $30.00 $5.40 $35.40 $35.00 $6.30 $41.30 $40.00 $7.20 $47.20 $45.00 $8.10 $53.10 $50.00 $9.00 $59.00 $55.00 $9.90 $64.90 $60.00 $10.80 $70.80 $65.00 $11.70 $76.70 $70.00 $12.60 $82.60 $75.00 $13.50 $88.50 $80.00 $14.40 $94.40 $85.00 $15.30 $100.30 $90.00 $16.20 $106.20 $95.00 $17.10 $112.10 $100.00 $18.00 $118.00 Press ENTER to exit...
There ya go. Add more tabs in spots to make it look nicer if you want. That will work for all values up to 1000, then you'll have to change some stuff up, but that's no big deal.
Awesome, thanks. Care to explain what that does exactly? I don't like putting things into my code if I don't know what they do.

edit: I see that it basically puts a tab wherever you put it, but what I'm curious about it why it doesn't put a set amount of space..

Does it just make it jump over to a specific column? And if so, I'm assuming you can change the number of columns in each tab, is that correct? (just out of curiosity, I don't need to do that at the moment)

edit2: Wee, got it all spaced out how I want it.



Thanks for the help!

Last edited by kif : 10-14-2008 at 12:24 PM.
kif is offline  
Old 10-14-2008, 12:34 PM #13
zellthemedic
GRAAAAAAA
 
zellthemedic's Avatar
 
Join Date: Apr 2007
Location: NAS Oceana, VA
zellthemedic helped look for balloons
zellthemedic is playing at Living Legends III
zellthemedic owns a Planet Eclipse Ego
zellthemedic is for the Gunfight
zellthemedic has achieved Level 3 in PbNation Pursuit
Quote:
Originally Posted by kif View Post
Thanks for the help!
Glad I could help!
__________________
After dark OT:T GDT crew: More RAM than the Himalayas
OT:T:G: We sometimes like gaming, but not really -- but we really like zombies

UNITED STATES NAVY
zellthemedic is offline  
Old 10-14-2008, 12:40 PM #14
chubby bunny
Puppies on Acid
 
chubby bunny's Avatar
 
Join Date: Sep 2004
Location: Ring 0
chubby bunny is a Supporting Member
Quote:
Originally Posted by kif View Post
Does anybody have a suggestion for what I should look up to find out how to get the spacing right?
Using tabs instead of spaces would be the easiest.

I'm working on a debugger that will visually represent objects in memory. It'll be a good tool for your data structures classes. It has a LONG way to and I'm currently learning to use some things right now:

<snip codes>
__________________
Gentoo Linux / ah.fm / "Old" Feedback
█ irc.oftc.net #doublethink

Last edited by chubby bunny : 10-26-2008 at 11:31 AM.
chubby bunny is offline  
Old 10-14-2008, 12:52 PM #15
boomslang
lo-fi
 
boomslang's Avatar
 
Join Date: Jul 2003
 has been a member for 10 years
Quote:
Originally Posted by chubby bunny View Post
Code:
class bananna {
Who is Anna and why would you want to ban her?? :o
__________________
Shoot the ****: irc.oftc.net #doublethink | dodgyaim
boomslang is offline  
Old 10-14-2008, 12:55 PM #16
CyanidePoison
 
 
CyanidePoison's Avatar
 
Join Date: Dec 2006
Location: La Porte, IN
harde-har-har
__________________
ST:T: We have subforums with more posts and threads than you.
CyanidePoison is offline  
Old 10-14-2008, 12:56 PM #17
durrell
 
 
Join Date: May 2004
Location: NC
 has been a member for 10 years
Quote:
Originally Posted by boomslang View Post
Who is Anna and why would you want to ban her?? :o
Annenbot?
durrell is offline  
Old 10-14-2008, 01:33 PM #18
zellthemedic
GRAAAAAAA
 
zellthemedic's Avatar
 
Join Date: Apr 2007
Location: NAS Oceana, VA
zellthemedic helped look for balloons
zellthemedic is playing at Living Legends III
zellthemedic owns a Planet Eclipse Ego
zellthemedic is for the Gunfight
zellthemedic has achieved Level 3 in PbNation Pursuit
Quote:
Originally Posted by durrell View Post
Annenbot?
<-- Has that song stuck in head now.
__________________
After dark OT:T GDT crew: More RAM than the Himalayas
OT:T:G: We sometimes like gaming, but not really -- but we really like zombies

UNITED STATES NAVY
zellthemedic is offline  
Old 10-14-2008, 01:55 PM #19
SonyLover
-
 
SonyLover's Avatar
 
Join Date: Dec 2004
Location: Austin, Texas
SonyLover is a Supporting Member
Quote:
Originally Posted by durrell View Post
Annenbot?
What I was thinking.

I r in Computer Science nao. We is learning Java.
__________________
ST:Tech - We gots 6 tetroflops of RAM
General Discussion Thread
SonyLover is offline  
Old 10-14-2008, 01:58 PM #20
CyanidePoison
 
 
CyanidePoison's Avatar
 
Join Date: Dec 2006
Location: La Porte, IN
Lol@Java
__________________
ST:T: We have subforums with more posts and threads than you.
CyanidePoison is offline  
Old 10-14-2008, 01:59 PM #21
zellthemedic
GRAAAAAAA
 
zellthemedic's Avatar
 
Join Date: Apr 2007
Location: NAS Oceana, VA
zellthemedic helped look for balloons
zellthemedic is playing at Living Legends III
zellthemedic owns a Planet Eclipse Ego
zellthemedic is for the Gunfight
zellthemedic has achieved Level 3 in PbNation Pursuit
Quote:
Originally Posted by CyanidePoison View Post
Lol@Java
.
__________________
After dark OT:T GDT crew: More RAM than the Himalayas
OT:T:G: We sometimes like gaming, but not really -- but we really like zombies

UNITED STATES NAVY
zellthemedic is offline  
Closed Thread


Thread Tools

Posting Rules
Forum Jump