Hello I am trying to get my end result to be lined up properly, but I'm having a hard time doing and understanding the process.
It should look like this as the output:
http://imgur.com/a/WQREu
But I'm getting really weird spacing issues. I know my setw() have strange number it was from me tinkering with the space to try and match them up.
I'm getting this:
-------------------------
Base Pay: $ 100.00
Medical fee: $ 24.00
Weight fee: $ 4.00
-------------------------
Subtotal: $ 128.00
Tax: $ 5.76
-------------------------
Total: $ 133.76
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;
int main () {
string name;
string petname;
string typeofpet;
int petweight;
int max=30;
int min=20;
float petweightfee;
float medicalfee;
double percentage_tax=4.5;
float total;
float salestax;
float subtotal;
float basepay=100.00;
unsigned seed = time(0);
srand(seed);
cout << "What is your full name? " << name;
getline(cin,name);
cout << "What is your pet type? "<< typeofpet;
getline(cin,typeofpet);
cout << "What is your pet's name? " << petname;
getline(cin,petname);
cout << "Weight of pet? ";
cin >> petweight;
cout << endl;
medicalfee = (rand() % max - min + 1) + min;
petweightfee = petweight * 0.5;
subtotal = petweightfee + basepay + medicalfee;
salestax = subtotal * (percentage_tax / 100);
total = salestax + subtotal;
cout << "Congragulations on adopting this critter!" << endl;
cout << name << ",the cost to adopt your new " << typeofpet << " " << petname << " who is " << petweight << " pounds is as follows: " << endl;
cout << "-------------------------" << endl;
cout << setprecision(2)<< fixed;
cout << "Base Pay:" << setw(9);
cout << " $ " << right << basepay << endl;
cout << "Medical fee:" << setw(6);
cout << "$ " << right << medicalfee << endl;
cout << "Weight fee:" << setw(7);
cout << "$ " << right << petweightfee << endl;
cout << "-------------------------" << endl;
cout << "Subtotal:" << setw(8);
cout << "$ " << right << subtotal << endl;
cout << "Tax:" << setw(15);
cout << "$ " << right << salestax << endl;
cout << "-------------------------" << endl;
cout << "Total:" << setw(10);
cout << "$ " << right << total << endl;
return 0;
}
|
Last edited on