Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Ways to Buy Pizza You, your roommate and another friend of yours want to buy som

ID: 3671336 • Letter: W

Question

Ways to Buy Pizza You, your roommate and another friend of yours want to buy some pizza. The problem is that each of you likes a different type of pizza. You've agreed on getting some slices of each of the three types of pizza the three of you like and have further determined that your friend will get the least number of slices of his type and you will get the most number of slices of your type. (All three of you will receive a different number of slices.) Write a program that prints out all the possible slice distributions given the total number of slices you all are buying. For each distribution, print out a line with the following format:

Friend = X slices, Roommate = Y slices, and You = Z slices

where X, Y and Z are the corresponding number of slices.

Sample Run (User input in bold and italics)

How many slices of pizza are you getting all together? 10

Friend = 1 slices, Roommate = 2 slices, and You = 7 slices

Friend = 1 slices, Roommate = 3 slices, and You = 6 slices

Friend = 1 slices, Roommate = 4 slices, and You = 5 slices

Friend = 2 slices, Roommate = 3 slices, and You = 5 slices

Explanation / Answer

#include <iostream>
#include <string>

using namespace std;

int main()
{
int n,roommate,fri,mine,count;
cout<<"How many slices of pizza are you getting all together? ";
cin>>n;

fri =1;

while(true)
{
    roommate = fri + 1;
    mine = n-roommate-fri;
    count = 0;
    while(roommate<mine)
    {
      count++;
      cout<<"Friend = "<<fri<<" slices, Roommate = "<<roommate<<" slices, You = "<<mine<<" slices ";
      roommate++;
      mine--;
    }
    fri++;
    if(count==0)
      break;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote