CPP
cpp
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
/*A supermarket has launched a campaign offering a 15% discount on 3 items. Write a program that takes the total price for every purchase as input and outputs the relavant discount.*/
#include <iostream>
using namespace std;
int main()
{
int purchaseAmount=3;
int totalPrice;
double discount=0.15;
double sum;
int x=1;
do{
x-=purchaseAmount;
x+=purchaseAmount;
cin>>totalPrice;
sum=totalPrice*discount;
cout<<sum<<endl;
x++;
} while (x<=3);
return 0;
} //input: 1500 1680 6930
//expected output: 225 252 1039.5
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run