Approach for simple problem - Beginner

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?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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.
Last edited on
Topic archived. No new replies allowed.