0

What is wrong with my C++ programme? (17.2 practise)

#include <iostream> using namespace std; int main() { int purchaseAmount = 0; double totalPrice; double output= totalPrice*0.15; do { cin>>totalPrice; cout<<output<<endl; ++purchaseAmount; } while(purchaseAmount<3); //your code goes here return 0; }

10th May 2022, 2:47 AM
Leapardbreeze
Leapardbreeze - avatar
3 Answers
+ 2
double output = totalPrice * 0.15; is not a definition of output that changes automatically every time, totalPrice gets a new value. It is an assignment, which will set output once, calculated from the current value of totalPrice. That means, you need to calculate output anew each time you read a new value into totalPrice.
10th May 2022, 4:05 AM
Ani Jona šŸ•Š
Ani Jona šŸ•Š - avatar
+ 1
Ani Jona šŸ•Š ah I see thanks :)
11th May 2022, 9:56 AM
Leapardbreeze
Leapardbreeze - avatar
+ 1
You're welcome :)
11th May 2022, 10:11 AM
Ani Jona šŸ•Š
Ani Jona šŸ•Š - avatar