need the output to have the decimal points lined up for any test data I decide to use. How could I do that in this code?. (The computer language that I am using is c++) #include #include //Define constant for tax rate #define taxRate 0.0788 using namespace std; int main() { //Set the precision to two decimal places cout << setprecision(2) << fixed; const double EXT_MONITOR=159.99; const double DELL_KEYB=18.30; const double DELL_MOUSE=16.45; const double WIND_OS=199.99; const double PRINTER=599.89; int extMonitor,d_keyboards,d_mouse,wind_OS,printer; double costEMonitor,costDell_key,cost_d_mouse,costWindOs,costPrinter; double total=0,subtotal,tax; //Get the required inputs from the user cout<<"How many External Monitor s were ordered? "; cin>>extMonitor; cout<<"How many Dell keyboards players were ordered? "; cin>>d_keyboards; cout<<"How many Dell Mouse units were ordered? "; cin>>d_mouse; cout<<"How many Windows 10 OS were ordered? "; cin>>wind_OS; cout<<"How many Network Printers were ordered? "; cin>>printer; //Compute cost for external monitor costEMonitor=EXT_MONITOR*extMonitor; //Compute cost for dell mouse cost_d_mouse=DELL_MOUSE*d_mouse; //Compute cost for dell keyboard costDell_key=DELL_KEYB*d_keyboards; //Compute cost for windows OS costWindOs=WIND_OS*wind_OS; //Compute cost for printer costPrinter=PRINTER*printer; //Compute cost for sub total subtotal=costEMonitor+costDell_key+cost_d_mouse+costPrinter+costWindOs; //Print the output cout<<"\nQTY Description Unit Price Total Price"<
I need the output to have the decimal points lined up for any test data I decide to use. How could I do that in this code?. (The computer language that I am using is c++)
#include <iostream>
#include <iomanip>
//Define constant for tax rate
#define taxRate 0.0788
using namespace std;
int main()
{
//Set the precision to two decimal places
cout << setprecision(2) << fixed;
const double EXT_MONITOR=159.99;
const double DELL_KEYB=18.30;
const double DELL_MOUSE=16.45;
const double WIND_OS=199.99;
const double PRINTER=599.89;
int extMonitor,d_keyboards,d_mouse,wind_OS,printer;
double costEMonitor,costDell_key,cost_d_mouse,costWindOs,costPrinter;
double total=0,subtotal,tax;
//Get the required inputs from the user
cout<<"How many External Monitor s were ordered? ";
cin>>extMonitor;
cout<<"How many Dell keyboards players were ordered? ";
cin>>d_keyboards;
cout<<"How many Dell Mouse units were ordered? ";
cin>>d_mouse;
cout<<"How many Windows 10 OS were ordered? ";
cin>>wind_OS;
cout<<"How many Network Printers were ordered? ";
cin>>printer;
//Compute cost for external monitor
costEMonitor=EXT_MONITOR*extMonitor;
//Compute cost for dell mouse
cost_d_mouse=DELL_MOUSE*d_mouse;
//Compute cost for dell keyboard
costDell_key=DELL_KEYB*d_keyboards;
//Compute cost for windows OS
costWindOs=WIND_OS*wind_OS;
//Compute cost for printer
costPrinter=PRINTER*printer;
//Compute cost for sub total
subtotal=costEMonitor+costDell_key+cost_d_mouse+costPrinter+costWindOs;
//Print the output
cout<<"\nQTY Description Unit Price Total Price"<<endl;
cout<<extMonitor<<setw(15)<<" EXTERNAL MONITOR "<<setw(6)<<EXT_MONITOR<<" "<<setw(6)<<costEMonitor<<endl;
cout<<d_keyboards<<setw(15)<<" DELL KEYBOARD "<<setw(6)<<DELL_KEYB<< " "<<setw(6)<<costDell_key<<endl;
cout<<d_mouse<<setw(15)<<" DELL MOUSE "<<setw(6)<<DELL_MOUSE<< " "<<setw(6)<<cost_d_mouse<<endl;
cout<<wind_OS<<setw(15)<<" WINDOWS OS "<<setw(6)<<WIND_OS<< " "<<setw(6)<<costWindOs<<endl;
cout<<printer<<setw(15)<<" NETWORK PRINTER "<<setw(6)<<PRINTER<< " "<<setw(6)<<costPrinter<<endl;
cout<<"\nSUBTOTAL "<<subtotal<<endl;
//Compute tax
tax=subtotal*taxRate;
//Compute total
total=subtotal+tax;
cout<<"TAX "<<tax<<endl;
cout<<"TOTAL "<<total<<endl;
return 0;
}
You should first use the alignment type and then use the setw command to format the output.
PROGRAM:
//Header file
#include <iostream>
#include <iomanip>
//Define constant for tax rate
#define taxRate 0.0788
using namespace std;
//Defining main
int main()
{
//Set the precision to two decimal places
cout << setprecision(2) << fixed;
const double EXT_MONITOR=159.99;
const double DELL_KEYB=18.30;
const double DELL_MOUSE=16.45;
const double WIND_OS=199.99;
const double PRINTER=599.89;
int extMonitor,d_keyboards,d_mouse,wind_OS,printer;
double costEMonitor,costDell_key,cost_d_mouse,costWindOs,costPrinter;
double total=0,subtotal,tax;
//Get the required inputs from the user
cout<<"How many External Monitor s were ordered? ";
cin>>extMonitor;
cout<<"How many Dell keyboards players were ordered? ";
cin>>d_keyboards;
cout<<"How many Dell Mouse units were ordered? ";
cin>>d_mouse;
cout<<"How many Windows 10 OS were ordered? ";
cin>>wind_OS;
cout<<"How many Network Printers were ordered? ";
cin>>printer;
//Compute cost for external monitor
costEMonitor=EXT_MONITOR*extMonitor;
//Compute cost for dell mouse
cost_d_mouse=DELL_MOUSE*d_mouse;
//Compute cost for dell keyboard
costDell_key=DELL_KEYB*d_keyboards;
//Compute cost for windows OS
costWindOs=WIND_OS*wind_OS;
//Compute cost for printer
costPrinter=PRINTER*printer;
//Compute cost for sub total
subtotal=costEMonitor+costDell_key+cost_d_mouse+costPrinter+costWindOs;
//Print the output
cout<<endl;
cout<<left<<fixed<<"QTY"<<"\t\tDescription"<<"\t\t\tUnit Price"<<"\t\tTotal Price"<<endl;
cout<<left<<fixed<<setw(7)<<extMonitor<<setw(21)<<" EXTERNAL MONITOR "<<setw(15)<<EXT_MONITOR<<" "<<setw(10)<<costEMonitor<<endl;
cout<<left<<fixed<<setw(7)<<d_keyboards<<setw(21)<<" DELL KEYBOARD "<<setw(15)<<DELL_KEYB<< " "<<setw(10)<<costDell_key<<endl;
cout<<left<<fixed<<setw(7)<<d_mouse<<setw(21)<<" DELL MOUSE "<<setw(15)<<DELL_MOUSE<< " "<<setw(10)<<cost_d_mouse<<endl;
cout<<left<<fixed<<setw(7)<<wind_OS<<setw(21)<<" WINDOWS OS "<<setw(15)<<WIND_OS<< " "<<setw(10)<<costWindOs<<endl;
cout<<left<<fixed<<setw(7)<<printer<<setw(21)<<" NETWORK PRINTER "<<setw(15)<<PRINTER<< " "<<setw(10)<<costPrinter<<endl;
cout<<left<<fixed<<setw(7)<<"\nSUBTOTAL "<<setw(21)<<subtotal<<endl;
//Compute tax
tax=subtotal*taxRate;
//Compute total
total=subtotal+tax;
cout<<left<<fixed<<setw(9)<<"TAX "<<setw(25)<<tax<<endl;
cout<<left<<fixed<<setw(9)<<"TOTAL "<<setw(25)<<total<<endl;
return 0;
}
Step by step
Solved in 2 steps with 1 images