Question #39680

I need an algorithm to be able to calculate cost when there is a sale for buy two get one free

Expert's answer

#include <iostream>
#include <cmath>


using namespace std;


int main()
{
int n = 0;
cout <<"Enter number of items please:
";
cin >> n;
double total = 0, temp = 0;
for (int i = 1; i <= n; ++i)
{
cout << "Enter price of item number " << i << ":
";
cin >> temp;
if (i % 3)
total += temp;
}

cout << "Total price: " << total;
cin.get(); cin.get();
return 0;
}
LATEST TUTORIALS
APPROVED BY CLIENTS