+ 3

Fruit bowl problem

Iā€™m solving this problem in c++, and thereā€™s something that i donā€™t get. It says you have an even amount of fruit, half apples, and half bananas. When coding, i tried to add an ā€œifā€ function, so that if the amount of fruit was odd, you couldnā€™t solve it because technically you canā€™t have an odd number of fruit in this problem, and in case the hypothetical user of this program tried to input an odd number, the program would tell them that. But it gave me trouble when solving, said three of the 5 answers were wrong (possibly because they had used odd numbers and my program was just saying it couldnā€™t be). However when i took that condition out, the program worked fine. Does that mean we have to overlook the info given in the problem?

29th Jan 2020, 11:23 PM
Silvia
14 Answers
+ 6
Please post your attempt and we'll be glad to help!
29th Jan 2020, 11:30 PM
Gevork Bagratyan
+ 4
#include <stdio.h> #include <stdlib.h> int main() { int fruit,banana,apple,pie; scanf("%d",&fruit); //your code goes here if(fruit>=6) { apple=fruit/2; pie=apple/3; printf("%d",pie); } else printf("0"); return 0; }
11th Aug 2020, 6:23 AM
PRABHU D
PRABHU D - avatar
+ 3
Coder Kitten i believe this is what i had before i changed it to the option that works, perhaps i did something wrong but i cannot see it hahaha #include <iostream> using namespace std; int main() { int fruit; //take input cin>>fruit; //your code goes here if (fruit>=6) { if (fruit%2!=0) { cout<<"cannot solve"; } else { cout<<(fruit/2)/3; } } else { cout<<0; } return 0; }
29th Jan 2020, 11:55 PM
Silvia
+ 3
Why u guys making it complex šŸ˜‚ #include <iostream> using namespace std; int main() { int fruit , result ; //take input cin>>fruit; result = fruit/6 ; cout <<""<<result; return 0; }
18th Sep 2020, 11:38 AM
Mantu kumar
Mantu kumar - avatar
+ 2
Gevork Bagratyan that was my guess as well, but i was trying to cover all the possibilities, since that could happen in a real life scenario. Maybe this app just expects it to be exact as you said, oh well, itā€™s fine, itā€™s good to know for the next time hahaha
30th Jan 2020, 12:27 AM
Silvia
+ 2
#include <bits/stdc++.h> using namespace std; int main() { int fruit; //take input cin>>fruit; //your code goes here int apple =fruit/2; int pie=apple/3; if(apple%pie>=2||1||0){ cout<<pie;} return 0; } here ya go
20th Mar 2020, 10:59 AM
100 subs with 2 videos
100 subs with 2 videos - avatar
+ 2
#include <iostream> using namespace std; int main() { int fruit; //take input cin>>fruit; //your code goes here int apple; int pie; int i=1; apple=fruit/2; if(apple<6){ cout<<0; } else{ while(i<apple){ i=i+3; pie++; } } cout<<pie; } This my code resolves upto test case #2,#3 and #5 and deliberately refuses #1, because there is an ouput of the form 00.... so why is it like this?
9th Sep 2020, 12:19 PM
Karol Charles Konarski
Karol Charles Konarski - avatar
+ 1
These problems expect exact outputs. I'm assuming that cout << "cannot solve" is the issue..?
30th Jan 2020, 12:05 AM
Gevork Bagratyan
+ 1
What's the problem in this code i cannot find the output.šŸ˜ž #include <iostream> using namespace std; int main() { int fruit,pie; cout<<"enter no.of fruits:" cin>>fruit; if(fruit%2==0) { fruit=fruit/2; } pie=fruit/3; cout<<"total pie ="<<pie; return 0; }
16th Mar 2020, 11:24 AM
Mayank kr
Mayank kr - avatar
0
Mayank kr, you missed ";" After your first cout string
19th Mar 2020, 2:05 PM
Maxim
Maxim - avatar
0
Maxim thanx bro
24th Apr 2020, 10:00 AM
Mayank kr
Mayank kr - avatar
0
Maxim thanx bro
24th Apr 2020, 10:00 AM
Mayank kr
Mayank kr - avatar
0
This is the exact thing I did, and it was giving me error too. But technically, according to the problem, this probability should be considered.
1st Aug 2020, 12:59 PM
Uni Quantum
Uni Quantum - avatar
0
int main() { int fruit; Cin>>fruit; int a; a= fruit/2*3; /*divided by 2 because we get half of fruit and alse divided by 3 because 3 apples make 1 pie, so total is 2*3=6 .. U can also write fruit/6...*/ Cout<<a; return 0; }
15th Jan 2023, 11:40 AM
Soni
Soni - avatar