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.
--Guido
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; }





Comment