need help fixing program

hi i am new to c++ and i really need your help, could you please show me what I'm doing wrong.

At the local supermarket, hotdogs are sold in packages containing a dozen (12) dogs, and yet hotdog buns are sold in packages containing 8 buns. One question we can ask is this: given some number of packages of dogs and buns, how many hotdogs can we make (one dog per bun)? In this problem, you'll answer that question.

Here is a description of what your program should do. After that is a description of how you should write the program.

Ask the user for the number of hotdog packages purchased.
Ask the user for the number of hotdog bun packages purchased.
If there are leftover dogs or buns, display what is left over, and how many.
Display to the console the number of hotdogs you can make (one dog per bun) without buying more dogs or buns.

For example, if you have 2 packages of dogs (24 dogs total), and 3 packages of buns (24 buns total), you can make 24 hotdogs, and nothing left over. But if you have 1 package of dogs, and 2 packages of buns, you can only make 12 hotdogs, but you will have 4 buns left over.

To solve this problem, you should write a function called hotdog(), which takes as input (e.g. function arguments):

The number of packages of dogs (12 dogs per package)
The number of packages of buns (8 buns per package)

Your hotdog() function should do the following steps:

Calculate how many complete hotdogs that can be made (1 dog per bun)
Calculate how many dogs or buns are left over (you can have zero leftovers)
If there are leftover dogs or buns, display (to the console) what is left over, and how many (display nothing if there are no leftovers).
Return the number of complete hotdogs you can make.

In main(), you should write code that does the following:

Ask the user for the number of hotdog packages purchased.
Ask the user for the number of hotdog bun packages purchased.
Call the function hotdog(), providing the correct information, and storing the result
Display to the console the number of hotdogs you can make (one dog per bun) without buying more dogs or buns.

Here's an example of how the program could work:

Wasteful Bro's Hotdog Restaurant Kitchen app!
Please enter how many packages of dogs you have: 1
Please enter how many packages of buns you have: 2
We have 4 buns leftover!
We can make 12 hotdogs!

Or this:

Wasteful Bro's Hotdog Restaurant Kitchen app!
Please enter how many packages of dogs you have: 2
Please enter how many packages of buns you have: 3
We can make 24 hotdogs!
#include <iostream>


using namespace std;

int main hotdogs () {
int x;
int y;
int calc1;
int calc2;

calc1 = (x - y);
calc2 = (x % y);

cout << "their are" << calc1 << " buns leftover" << endl;
cout << "their are" << calc2 << " dogs leftover" << endl;


return (x-y);
}

int main ()
{
int x;
int y;

cout << "The number of packages of dogs: ";
cin >> x;
cout << "The number of packages of buns: ";
cin >> y;
x = hotdogs(12*x, 8*y);

cout << hotdogs << "can be made" << endl;

return 0;
}
1. Put your code between [ code ] tags so it is easier to read.
2. There is no variable called "hotdogs" in main. You might have been looking for x?
Last edited on
I like to use variables that make sense.
I think this is what your looking for?
If you want to use modulus, you can display the leftovers in total packages and buns/dogs leftover.


<code>
#include <iostream>
using namespace std;

void hotdogs(int dogs, int buns);


void hotdogs(int pkgDogs, int pkgBuns)
{
int totalDogs,totalBuns;
totalBuns = pkgBuns*8;
totalDogs = pkgDogs *12;

if (totalBuns >= totalDogs)
{
cout << "We can make "<< totalDogs << " hot dogs!\n";
cout << "There will be "<< totalBuns - totalDogs << " buns left over.\n";
}

if ( totalDogs >= totalBuns)
{
cout << "You can make "<< totalBuns<<" hot dogs!\n";
cout << "We will have "<<totalDogs-totalBuns<<" dogs left over.\n";
}


}

int main ()
{
int pkgDogs;
int pkgBuns;

cout << "Wasteful Bro's Hot Dog Restaurant Kitchen app!\n";
cout << "Please enter how many packages of dogs you have:\n";
cin >> pkgDogs;
cout << "Please enter how many packages of hot dog buns:\n";
cin >> pkgBuns;

hotdogs(pkgDogs, pkgBuns);

return 0;
}
<code>
Last edited on
I see that you wanted nothing mentioned if there was no leftovers.
Here is the correction:

[code]
if (totalBuns > totalDogs)
{
cout << "We can make "<< totalDogs << " hot dogs!\n";
cout << "There will be "<< totalBuns - totalDogs << " buns left over.\n";
}

if ( totalDogs > totalBuns)
{
cout << "You can make "<< totalBuns<<" hot dogs!\n";
cout << "We will have "<<totalDogs-totalBuns<<" dogs left over.\n";
}

if (totalDogs == totalBuns)
cout<< "You can make "<< totalBuns<<" hot dogs!\n";

[code]
Topic archived. No new replies allowed.