Quote (labatymo @ Sep 20 2013 04:57pm)
The problem was tax wasn't initialized and you were declaring a local variable "first_price" for the for loop and as an int, which adding a decimal (first_place += price_step) will do nothing, causing infinite loop.
Code
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double tax;
double taxperunit;
double first_price;
double pricewithtax;
double last_price = 0;
double price_step = 0;
double tax_percentage = 0;
cout << setw(5) << "Price without tax" << setw(15) << "Tax" << setw (15) << "Price with tax" << endl;
cout << setw(50) << setfill('=') << "=" << endl;
cout << setfill(' '); // fill spaces in the next write operations
cout << "Enter first price= " << endl;
cin >> first_price;
cout << "Enter last price= " << endl;
cin >> last_price;
cout << "Price step= " << endl;
cin >> price_step;
cout << "Tax percentage= " << endl;
cin >> tax_percentage;
for(double i = first_price; i<= last_price;i+=price_step){
tax = i * (tax_percentage /100);
cout << i << "\t" << tax << "\t" << tax+first_price <<endl;
}
return 0;
}
It should actually be this:
for(double i = first_price; i<= last_price;i+=price_step){
tax = i * (tax_percentage /100);
cout << i << "\t" << tax << "\t" <<
tax+i<<endl;
}
But other than that, it should work
This post was edited by ShadowFiend on Sep 20 2013 02:15pm