cout<< "Please enter the company's name: " ;
cin>> company_name;
cout<< "Please enter the total sales: " ;
cin>> total_sales;
if (total_sales<15000) {
cout<< "The total sales is : " <<total_sales <<std::endl;
sales=total_sales * 0.025;
cout<< "the sales is: " <<sales <<endl;
sales_after_tax=total_sales- sales;
cout<< "The sales after tax is: " <<sales_after_tax <<std::endl;
}
else if (total_sales>=15000 && total_sales<25000) {
cout<< "The total sales is: " <<total_sales <<std::endl;
sales=total_sales * 0.4;
cout<< "The sales is: " <<sales <<std::endl;
sales_after_tax= total_sales - sales;
cout<< "The sales after tax is: " <<sales_after_tax <<std::endl;
}
else if (total_sales>=25000 && total_sales<=35000) {
cout<< "The total sales is: " <<total_sales <<std::endl;
sales=total_sales * 0.07;
cout<< "The sales is: " <<sales <<std::endl;
sales_after_tax=total_sales- sales;
cout<< "The sales after tax is: " <<sales_after_tax <<std::endl;
}
else if (total_sales>35000) {
cout<< "The total sales is: " <<total_sales <<std::endl;
sales=total_sales * 0.1;
cout<< "The sales is: " <<sales <<std::endl;
sales_after_tax=total_sales- sales;
cout<< "The sales after tax is: " <<sales_after_tax <<std::endl;
general rule for making counters:
declare the counter just before entering the loop that you want to keep a count of, initialized counter to 0 (assuming you want to count upwards)
test the boundary state of the counter as one of the loop conditions
increment counter after each iteration of the loop
so, in your program, if you only wanted to enter data for 3 companies and their total_sales for example, you could do something like:
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <math.h>
#include <iostream>
usingnamespace std;
autoconstexpr SIZE = 3;
int main ()
{
std::string company_name;
double total_sales=0;
double sales_tax=0;
double sales_after_tax=0;
double sales;
size_t counter {};
while (counter < SIZE)
{
cout<< "Please enter the company's name: " ;
cin>> company_name;
cout<< "Please enter the total sales: " ;
cin>> total_sales;
if (total_sales<15000) {
cout<< "The total sales is : " <<total_sales <<std::endl;
sales=total_sales * 0.025;
cout<< "the sales is: " <<sales <<endl;
sales_after_tax=total_sales- sales;
cout<< "The sales after tax is: " <<sales_after_tax <<std::endl;
}
elseif (total_sales>=15000 && total_sales<25000) {
cout<< "The total sales is: " <<total_sales <<std::endl;
sales=total_sales * 0.4;
cout<< "The sales is: " <<sales <<std::endl;
sales_after_tax= total_sales - sales;
cout<< "The sales after tax is: " <<sales_after_tax <<std::endl;
}
elseif (total_sales>=25000 && total_sales<=35000) {
cout<< "The total sales is: " <<total_sales <<std::endl;
sales=total_sales * 0.07;
cout<< "The sales is: " <<sales <<std::endl;
sales_after_tax=total_sales- sales;
cout<< "The sales after tax is: " <<sales_after_tax <<std::endl;
}
elseif (total_sales>35000) {
cout<< "The total sales is: " <<total_sales <<std::endl;
sales=total_sales * 0.1;
cout<< "The sales is: " <<sales <<std::endl;
sales_after_tax=total_sales- sales;
cout<< "The sales after tax is: " <<sales_after_tax <<std::endl;
}
++counter;
}
}