Joe is fond of chocolates. He has initially A dollars and a single chocolate costs B dollars but Joe cannot buy more than C chocolates. Find the number of chocolates Joe can buy with the money he has.
I have figured out on paper for ex A=10,B=3,C=4 Output = 3. Since Joe has only 10 dollars he can buy only 3 chocolates. How do I code this in cpp?
int main()
{
//Our Constant Variables, Numbers from your example
int a = 10;
int b = 3;
int c = 4;
int answer; //Variable to Hold Calculation.
answer = a / b; //How many cookies Joe can buy with ALL his money
if (answer > c) //If he can buy more cookies than he is allowed, output the allowed amount
{
std::cout << "Joe Can Buy " << c << " Cookies!";
}
else //Otherwise, output the amount he can buy with the money he has
{
std::cout << "Joe Can Buy " << answer << " Cookies!";
}
}
If you have a question about this feel free to ask.