0
could you please help me,For solving the fruit bowl challange with c++.
#include <iostream> using namespace std; int main() { int fruit; //take input cin>>fruit; if(fruit %3==1){ cout <<"The apples are:"<<fruit ; } else if(fruit %2==0){ cout <<"The pies are:"<< fruit ; } return 0; } /*the give before code is written by me, inthis code any false ?,please correct and teach for how to write the correct code for this challange! */
2 Respuestas
+ 4
ILLUMINATIE
The problem is asking how many pie can you make with the fruits?
Criteria for making pie:
3 apples make 1 pie.
So it's simple to find number of pies using number of apples
Mathematically, we have
num_of_pie = (no_of_apple)/3 -- -- -> (1)
Also its given in question that out of total number of fruits inputted half are bananas and half are apples.
So, now we can find the number of apples easily,
no_of_apple = fruit / 2
equation(1) becomes,
num_of_pie = (fruit/2)/3
for outputting just print num_of_pie
--------------------
fruit = 0;
cin >> fruit ;
cout << (fruit/2)/3;
--------------------
0
Is it code coach?
Edit:
You just have to find how many pies can be made with input..
ILLUMINATIE
Among all input of fruits:
Half are banana, half are apples. Put bananas aside..
How many inputs of apples you have..? N (half of input)
3 apples make 1 pie..
N apples make how many pies..? M
Find N, M.
M is answer.