-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathratfood.cpp
More file actions
33 lines (31 loc) · 819 Bytes
/
ratfood.cpp
File metadata and controls
33 lines (31 loc) · 819 Bytes
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 foodcount(int r,int units, int n, int arr[])
{
int totalfoodreq=r*units;
int food=0;
int house;
for(house = 0; house<n; house++)
{
food+=arr[house];
if(food>=totalfoodreq) break;
}
if(totalfoodreq>food) return 0;
else return (house+1);
}
int main()
{
int r,units,n,arr[n];
cout<<endl<<"Enter the number of Rats: ";
cin>>r;
cout<<endl<<"Enter the units consumed by 1 Rat: ";
cin>>units;
cout<<endl<<"Enter the number of houses: ";
cin>>n;
for(int i = 0;i<n;i++){
cout<<"Enter the number of units in house: "<<i<<endl;
cin>>arr[i];
}
int count = foodcount(r,units,n,arr);
cout<<endl<<"No. of hosues the Rats has to pay a visit is: "<<count;
}