+ 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?
14 odpowiedzi
+ 6
Please post your attempt and we'll be glad to help!
+ 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;
}
+ 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;
}
+ 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;
}
+ 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
+ 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
+ 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?
+ 1
These problems expect exact outputs. I'm assuming that cout << "cannot solve" is the issue..?
+ 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;
}
0
Mayank kr, you missed ";" After your first cout string
0
Maxim thanx bro
0
Maxim thanx bro
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.
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;
}