my bad. so I wrote this
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 29 30 31 32 33
|
#include <iostream>
using namespace std;
int initial, out, remaining, emergency, day;
int main()
{
cout<<"Enter initial supply of oil (Litre(s)): ";
cin>>initial;
cout<<"Enter how many amount of oil taken out per day (Litre(s)): ";
cin>>out;
emergency=0.1*initial;
cout<<"Initial supply of oil is "<<initial<<" litre(s)";
cout<<"\nEmergency is at "<<emergency<<" litre(s))\n";
remaining=initial;
day=1;
while (remaining>=emergency)
{
remaining=remaining-out;
cout<<"\nDay "<<day<< "amount of oil is "<<remaining<<" litre(s)";
if (remaining<=emergency)
{
cout<<"\n**Warning, oil capacity is less than 10%**";
}
day++;
}
return 1;
}
|
It worked just fine, but there's a bit faulty.
I enter the initial input as 100, and out as 10
Then the output looked like this
------------------------------------------
Day 1 amount of oil is 90 litre(s)
Day 2 amount of oil is 80 litre(s)
Day 3 amount of oil is 70 litre(s)
Day 4 amount of oil is 60 litre(s)
Day 5 amount of oil is 50 litre(s)
Day 6 amount of oil is 40 litre(s)
Day 7 amount of oil is 30 litre(s)
Day 8 amount of oil is 20 litre(s)
**Warning , oil capacity is less than 10%**
Day 9 amount of oil is 10 litre(s)
**Warning , oil capacity is less than 10%**
Day 10 amount of oil is 0 litre(s)
------------------------------------------
Supposedly, the emergency amount based on the input is at 10litres
Can someone please correct my coding so that the if statement would ONLY appear after Day 9, and the loop should stop at Day 9 meaning Day 10 never existed
p/s: sorry for my bad explanation if you find it was hard to understand