C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



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:
  #1  
Old February 9th, 2004, 11:44 PM
Wolf_22 Wolf_22 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 6 Wolf_22 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 38 m 37 sec
Reputation Power: 0
Send a message via Yahoo to Wolf_22
C++ Help!!!

Okok, I'm new here so be gentle...

Ok, I need help w/ some simple programming stuff. So, tell me why this lil snippet doesn't want to work:

cout << "The cost of carpet is: $";
cout << (price_per_yard*(((length_ft*width_ft)/2)/3))*STAX;

STAX is a const of a couple bucks.
length_ft is an integer
width_ft is also an integer
price_per_yard is an float.

All of this crap is to a program I'm TRYING to write to compute carpet sales, and this lil part right here is the part that is supposed to compute the cost of the carpet after taking into affect the sales tax, square yards, and price per yard... Anyone have any suggestions cause I've tried everything... Thanks.

Reply With Quote
  #2  
Old February 10th, 2004, 08:22 AM
SHivan SHivan is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 10 SHivan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I dont understand why you would want to devide something by 2 and then devide it by 3, why not simply devide it by 6?

It may not solve your problem, but it will make it a lot easier to find your mistake

Reply With Quote
  #3  
Old February 10th, 2004, 12:27 PM
Wolf_22 Wolf_22 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 6 Wolf_22 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 38 m 37 sec
Reputation Power: 0
Send a message via Yahoo to Wolf_22
Help!

The reason is because length_ft multiplied by width_ft and then divided by 2 gives me the square footage of the room. Well, after THAT, I have to convert the square footage to square yards. So, I didvide it by 3... ANYONE know how to help me in this?

Reply With Quote
  #4  
Old February 11th, 2004, 08:59 AM
SHivan SHivan is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 10 SHivan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Have you tried the following?

float total = 0;
total = legth_ft*width_ft;
total = total/6;
total = total * STAX;
total = total * price_per_yard;
cout << "The cost of carpet is: $";
cout << total;

This isn't a good way to program I know, but if this works you can try to put the puzzle together one piece at a time and find out where the problem is located


Greetz

Reply With Quote
  #5  
Old February 12th, 2004, 05:08 AM
Buster77 Buster77 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 28 Buster77 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I'm gonna assume your main problem is that you are not getting the right answer, so I'm not gonna address issues like whether or not the code should be seperated to be more readable. The basic problem is that if you do ANY operation with an integer, the answer will be an integer. You need to cast the integers to type double (or float, if you must) and use constants of type double (of course, you don't have to permanently change the type of your declared constant if you don't want to). So the formula would look like this:

cout << (price_per_yard*(((static_cast<double>length_ft*static_cast<double>width_ft)/2.0)/3.0))*static_cast<double>STAX;

Now, I have used double because I would declare price_per_yard as a double (just a thang...), I am, however, 99.9% sure you could just change everywhere I have double to float... Just note also that where you divide by 2 and then 3, you need to divide by 2.0 and 3.0.

Hope this helps...

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > C++ Help!!!


Developer Shed Advertisers and Affiliates


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

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap