In: Computer Science
Input the available amount of Rice in kg. Write a program that reads a sequence of Rice donations in kg and add them to the initially available amount of Rice. The loop should stop once the accumulated amount of Rice exceed 50 kg. Then, the program should print the final amount of Rice and the number of considered donations.
#include<bits/stdc++.h>
using namespace std;
int main()
{
// Input the available amount of rice
cout<<"Enter the available amount of rice: ";
int avl_rice; cin>>avl_rice;
cout<<"\n";
// sum var keeps accumulated sum
int sum=avl_rice,val,no_of_donations=0;
// while loop continues till accumulated sum is smaller than 50
while(sum<=50)
{
// enter the amount of donation
cout<<"Enter the donation amount: ";
cin>>val;
sum+=val;
no_of_donations++;
}
cout<<"\n";
// print the final amount of rice and the total count of donations
cout<<"Final amount of rice: "<<sum<<"\n";
cout<<"Number of considered donations: "<<no_of_donations<<"\n";
cout<<"\n";
return 0;
}
PLEASE LIKE THE SOLUTION :))
IF YOU HAVE ANY DOUBTS PLEASE MENTION IN THE COMMENT