09-15-2005, 02:38 PM | #1 |
lil j the bad b-word
|
C++ Help
I need someone who's good at C++ to maybe make me this code. It's probably really basic for someone who's knowledgable about it but I got really confused. I can just check this thread and copy and paste it into there tomorrow.
Programming Project: ProfitMargin To make a profit, a local store marks up the prices of its items by a certain percentage. Write a C++ program that reads the original price of the item sold, the percentage of the marked-up price, and the sales tax rate. The program then outputs the original price of the item, the percentage of the mark-up, the store's selling price of the item, the sales tax rate, the sales tax, and the final price of the item. (The final price of the item is the selling price plus the sales tax. Thanks >_>
__________________
|
09-15-2005, 03:32 PM | #2 |
Summer!!
|
RE: C++ Help
That isn't C++, that's math
If you're familiar with how to cin and cout stuff, it's really all about knowing what kind of math is involved. I can't remember how variables are stored in C++, but my first suggestion for you is to take out a sheet of paper, and do one practice input.
__________________
|
09-15-2005, 04:02 PM | #3 |
FFR Player
|
RE: C++ Help
You can use Doubles/Floats and <iomanip.h>'s set preceision function, if you've learned it. The math involved is really easy, unless you have a weird taxation percent in New Jersey.
__________________
Signature subject to change. THE ZERRRRRG. |
09-15-2005, 04:08 PM | #4 |
lil j the bad b-word
|
RE: C++ Help
what.
__________________
|
09-15-2005, 04:15 PM | #5 | |
FFR Player
|
Re: C++ Help
Quote:
Secondly, you need to just know math. Just use the variable type "float" for the variable in this case. Thirdly, you need to know how to convert from a string or char* to a floating point number. I use my own String class library, so I am not sure if the standard library contains a method for converting strings to integers or floats. -----Soccr743----- |
|
09-15-2005, 04:18 PM | #6 |
FFR Player
|
RE: Re: C++ Help
Why/how on Earth would you go from char/string to a float?
__________________
Signature subject to change. THE ZERRRRRG. |
09-15-2005, 04:23 PM | #7 |
lil j the bad b-word
|
RE: Re: C++ Help
Keep in mind i've been in C++ for a week, and I have no fucking clue what you're talking about. It doesn't matter what the numbers are, i'm just confused with what to put.
The only reason i'm posting is because i'm a day behind in my class. So while everyone is on addictinggames, i'm sitting there confused with this goddamn thing.
__________________
|
09-15-2005, 04:27 PM | #8 |
FFR Player
|
RE: Re: C++ Help
Qreepy, you read from the console into the buffer which is in char* format... Then, you would need to convert that to a float in order to use it in calculations.
I would talk with you on AIM about it Eva, but I have a boatload of homework and you bloxed meh -----Soccr743----- |
09-15-2005, 04:28 PM | #9 |
Away from Computer
|
RE: C++ Help
I can do C, but I'm guessing its mostly the same except for minor syntactical stuff <_<
Code:
main() { float oprice, taxrate, markup,fprice,sprice,tax; printf("print the original price, tax rate percentage, and markup percentage") scanf("%f %f %f",&oprice,&taxrate,&markup); sprice = oprice * (1 + (markup/100) ); taxprice = sprice * (1 + taxrate/100); fprice = sprice + taxprice; printf("original price is %f \n markup is %f \n taxrate is %f \n",oprice,markup,taxrate") printf("store price is %f \n sales tax is %f \n final price is %f\n",sprice,tax,fprice"); } I don't know the syntax for couts and cin >_< would someone like to tell me Is it just the same but with << >> instead of () ? EDIT: PS, in C to go from string to int its stoi(insertstringhere) and you have to #include <stdlib.h> and stof for string to float ftoi, itof, they're all there <_< itos ftos <_<
__________________
|
09-15-2005, 04:38 PM | #10 |
lil j the bad b-word
|
RE: C++ Help
That's COMPLETELY different.
Soccr, I unblocked you a while ago rofl wtg
__________________
|
09-15-2005, 04:51 PM | #11 |
Away from Computer
|
RE: C++ Help
after getting some rudimentary C++ syntax help <_<
Code:
#include <iostream> main() { float oprice, taxrate, markup,fprice,sprice,tax; cout<<"print the original price, tax rate percentage, and markup percentage"; cin>>oprice>>taxrate>>markup; sprice = oprice * (1 + (markup/100) ); taxprice = sprice * (1 + taxrate/100); fprice = sprice + taxprice; cout<<"original price is",oprice; cout<<"markup is",markup; cout<<"taxrate is",taxrate; cout<<"store price is",sprice; cout<<"sales tax is",tax; cout<<"final price is",fprice; } and also I don't know what lib to include is it #include <iostream> ? this should be slightly less way different, I hope <_< EDIT: Edited in iostream
__________________
|
09-15-2005, 05:24 PM | #12 |
Resident Penguin
|
RE: C++ Help
yeah it's <iostream>
chicken's program should work. |
09-15-2005, 05:47 PM | #13 |
FFR Player
|
RE: C++ Help
I question this line:
"cin>>oprice,taxrate,markup;" Seems as though it should be this: "cin >> oprice >> taxrate >> markup;" But again, I don't do much work with the console. -----Soccr743----- |
09-15-2005, 05:50 PM | #14 |
Away from Computer
|
RE: C++ Help
Well I don't either, if you're right, then I'll edit it in, so does anyone else know?
EDIT: I just realized that was soccr speaking so uh <_< I'll go ahead and change that
__________________
|
09-15-2005, 06:00 PM | #15 |
FFR Player
|
RE: C++ Help
Hell, me speaking does not mean I am right... Especially when it comes to console programming. I really only did this stuff like a year ago when I first started and have since then moved from SDL to DirectX.
-----Soccr743----- |
09-15-2005, 06:32 PM | #16 |
is against custom titles
|
I'm somewhat certain that you can't read in several variables in one line, but if you can, Soccr's corrected line is the way to read the input. Otherwise, just have three different lines.
Also, you can directly read in an int, double, char, string, or what have you. chickendude had a pretty good code, but I'd make some modifications to it. By the way, every program where I had to do it, I went through hell trying to get the program to correctly output decimal values like I wanted (like showing prices with all the necessary trailing zeroes), so if my code for it looks complicated, it is, but it works. Assuming all the math is correct, this should read everything in properly and output everything you need with correct precision. Code:
#include <iostream> #include <iomanip> using namespace std; void main() { double oprice, taxrate, markup, fprice, sprice, tax; cout.setf(ios::floatfield | ios::showpoint); cout<<setprecision(2); cout<<"Input the original price, tax rate percentage, and markup percentage"; cin>>oprice; cin>>taxrate; cin>>markup; sprice = oprice * (1 + (markup/100) ); taxprice = sprice * (1 + taxrate/100); fprice = sprice + taxprice; cout<<"Original price is $"<<oprice<<endl; cout<<"Markup is $"<<markup<<endl; cout<<"Taxrate is $"<<taxrate<<endl; cout<<"Store price is $"<<sprice<<endl; cout<<"Sales tax is $"<<tax<<endl; cout<<"Final price is $"<<fprice<<endl; } http://andy.mikee385.com |
09-15-2005, 06:42 PM | #17 |
Away from Computer
|
RE: C++ Help
Ok, I looked it up, you were right
see soccr, you are always right <_<
__________________
|
09-15-2005, 06:48 PM | #18 |
FFR Player
|
RE: C++ Help
man, i feel so behind because i'm taking a Java/VBNet course.
__________________
|
09-15-2005, 07:00 PM | #19 | |
lil j the bad b-word
|
Quote:
This is somewhat along the lines of it, but the thing is he isn't asking for the Original price, he isn't asking for the markup, he's not asking for the tax rate. He's only asking for the New Price. That is, after markup and taxes. Here's some formulas I had wrote out on paper in class today: sellingPrice=originalPrice+addPrice addPrice=originalPrice*markupPrice newPrice=? Like I said, i've only been doing this for a week. Well here's kind of what it had looked like "Enter the original price of the item: *random number* Enter the mark-up percentage: *random number/decimal* Enter the tax-rate: *random number/decimal*" There has to be formulas that will calculate the newPrice after it's marked up and taxes are applied. Such as oP = 5 markup= .5 (50%) taxrate= .18 (18% i guess) After I figured this out, I got completely lost of what I had to enter the rest of the way... It started out like int originalPrice cout<<"Enter the original price of the item. "; cin>>price; cout<<endl; double markupPrice cout<<Enter the markup price. "; and so on... Hope I clarified some things >_> But Guido's looked somewhat close.
__________________
|
|
09-15-2005, 07:05 PM | #20 |
Away from Computer
|
The 'Final Price' (using the variable fprice)
is the new price I assumed you put in percentages for salestax and markup like 5% sales tax and 20% markup tax = storeprice * (1 + (taxrate/100) ) it just makes the % into a fraction and add one so it increases (so its x1.05 not x.05) then storeprice = originalprice * (1 + (markup/100) ) same reasoning and new price = storeprice + tax thats what I did in my program, and guido made syntax updates
__________________
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|