# Thread: Gas/Oil program for class

1. ## Gas/Oil program for class

Ok heres the problem right from the book. I just need you guys to review the problem and my code, and check that i did this right cuz i am a little unsure as to its accuracy. Thanks!

Problem:

Al Wildcat, owner of Wildcat Welling, wants a program that will help him decide wether or not a well is making money. Take in a single character, G for Gas, O for Oil, and D for dry well. Then take in the cost of the well, ie maintaining it. Ask the user if there was sulfer found in the well or not, if so prompt for percentage. Unit prices are \$5.50 for oil and \$2.20 for gas. These are to be defined as constants.

Program should find the total revenue of a well, reducing where sulfer is found based on the percentage. A gusher is a well in excess of \$50,000.

Code:
```/**************************************
*	Steven Billington
*	November 4, 2002
*	SwitchGAS.cpp
*
*	The purpose of this program is to find the value of a Gas or
*	Oil well based on the users input and the value of Gas and/or
*	Oil.
**************************************/

#include <iostream.h>
#include <ctype.h>
#include <stdlib.h>
#include <iomanip.h>

const double GAS_PRICE = 2.20;
const double OIL_PRICE = 5.50;

int main ()
{

char gastype,sulfer;
double cost, percentage, final,volume,newvolume,profitorloss;

cout<<"\nGas (G)\nOil (O)\nDry (D)\n";
cout<<"Enter choice: ";
cin>>gastype;

cout<<"\nEnter the cost of the well: ";
cin>>cost;

cout<<"\nEnter the well volume: ";
cin>>volume;

cout<<setiosflags(ios::fixed | ios::showpoint | ios::right)
<<setprecision(1);

gastype = toupper(gastype);

switch (gastype)
{
case 'G':	cout<<"\nWas sulfer found in the well?\nNo (N)\nYes (S) : ";
cin>>sulfer;
sulfer = toupper(sulfer);

switch (sulfer)
{
case 'N':	break;

case 'S':	cout<<"\nEnter the percentage: ";
cin>>percentage;

newvolume = percentage * volume;

volume = volume - newvolume;

final = volume * GAS_PRICE;

profitorloss = final - cost;
break;
}

break;

case 'O':	cout<<"\nWas sulfer found in the well?\nNo (N)\nYes (S) : ";
cin>>sulfer;
sulfer = toupper(sulfer);

switch (sulfer)
{
case 'N':	final = volume * OIL_PRICE;
profitorloss = final - cost;
break;

case 'S':	cout<<"\nEnter the percentage: ";
cin>>percentage;

newvolume = percentage * volume;

volume = volume - newvolume;

final = volume * OIL_PRICE;

profitorloss = final - cost;
break;
}

break;

case 'D':	cout<<"\nDry Well\n";
break;

break;
}

if (profitorloss >= 50000.00)
{
cout<<"Gusher!\n"<<profitorloss<<"\n";
}

else:
cout<<"Revenue for this well is "<<profitorloss<<".\n";

return 0;
}```

2. lol rideordie, try to replace the tabs with spaces after you copy/paste. It makes the code easier to read

3. Well it doesn't compile - at the end you have
> else:
Which might be a 'goto' label, then again it might not
i pasted the messed up version, sorry. Thank you for correcting the missing calc, i added that after i had copy/pasted the second code block, and forgot to add it again for the other condition.

Sorry for the formatting, and i perfer \n for its easier use, i never knew it was a negative habit.