You are using a version without Ads of this website. Please, consider donating:

### School Assignment - I'm so close to "getting" it.

Okay, I'm going to preface this by saying I don't take this forum for granted, and the help I've received from this forum (simply by reading previous threads).

I'm taking my 1st CS class and I'm stuck on this current assignment. If anybody could guide me in the right direction, that would be amazing.

Directions (copy and pasted from teacher document):

I am planning on becoming a viticulturist (wine maker). I need to know how many bottles of wine I can expect from my grape vines per year, given the size of my grape fields in acres. I also need to know the wine yield in gallons per year.

Assume a ton of grapes makes about 152.5 gallons of wine. About 2.377 gallons of wine are required to fill a case of twelve 750ml bottles.

An established vineyard can produce about 6.2 tons of grapes per acre per year.

Sample Dialog

Welcome to John Doe’s Viticulture Program.
How many acres of grape vines are you growing?
Acres: 9.5
The number of bottles of wine you can expect is: 45345
This is equivalent to 8982.25 gallons.
Thank you for using John Doe’s Viticulture Program.

This is what I have so far. I'm so close to understanding it, but I feel like I'm missing some command or something.

#include <iostream>

using namespace std;

void main()
{
double x;
double y;
double z;

cout << "Welcome to John Doe's viticulture program!" << endl;

cout << "How many acres of grape vines are you growing?" << endl;

cout << "Acres: ";
cin >> x;
cin >> y;

cout << "The number of bottles of wine you can expect is: ";

cout << x * 6.2 = y >> y * 152.5 = z;

system("pause");

}

Basically, what I'm trying to do is tell the program to do this;

x = the users input for how many acres they are growing on.
Then I tell the computer to do

x(6.2)= y
y(152.5)=z
Z = gallons of wine.

I'm struggling with when to use cin >>

I feel like I'm close to finishing this, but I'm not sure how to tell the program to keep doing more and more steps of arithmetic.

As stated, any help would be vastly appreciated. Thank you.
Last edited on
assignment must be left->right. And you don't need to cin y because your assignment later in the program will overwrite the inputted value.

 ``12345678910111213141516171819202122232425262728293031323334`` ``````#include using namespace std; void main() int main() { double x; double y; double z; cout << "Welcome to John Doe's viticulture program!" << endl; cout << "How many acres of grape vines are you growing?" << endl; cout << "Acres: "; cin >> x; cin >> y; cout << "The number of bottles of wine you can expect is: "; y = x * 6.2; z = y * 152.5; cout << "Z: " << z << endl; cout << "Y: " << y << endl; cout << x * 6.2 = y >> y * 152.5 = z; system("pause"); return 0; }``````
Thank you for the awesome reply.

I've been chewing on this for the last few hours and this is what I have

double x;
double y;
double z;

cout << "Welcome to John Doe's viticulture program!" << endl;

cout << "How many acres of grape vines are you growing?" << endl;

cout << "Acres: ";

cin >> x;

cout << "The number of bottles of wine you can expect is: ";

cout << x * 6.2 * 152.5 / 2.377 * 12 << endl;

cout << "This is equivalent to: ";

cout << x * 6.2 * 152.5;

cout << " gallons" << endl;

cout << "Thank you for using John Doe's Viticulture Program." << endl;

system("pause");

Is the above work correct? This is my 'finished' product to the best of my abilities, and the program does what I say.

I've left out the #include <oistream stuff, etc. Just giving you guys the guts.

My question is this: My finished product shows a decimal, and the assignment says I can't have decimals. How do I make it so I can't get decimals?

Our teacher told us "cout >> precision(2);" as a tip, but I tried "cout >> precision(0)" but I couldn't figure anything out.

Any help would be appreciated. Also, TheJJJunk, I haven't compiled your finished product yet, and our programs are very different. Is one superior compared to the other?

Thanks for taking the time to help guys, honestly!

 Is the above work correct?
Yes it works.

 How do I make it so I can't get decimals?
You could assign the value that you want to display to an int, however there will be rounding errors:

`int a = x * 6.2 * 152.5 / 2.377 * 12;`

 our programs are very different. Is one superior compared to the other?
My program is syntactically correct, however it is just for the sake of an example.

And also, if you use your code, you do not need
 ``12`` ``````double y; double z;``````
Last edited on
Topic archived. No new replies allowed.

You are using a version without Ads of this website. Please, consider donating: