# I'M CONFUSED ON HOW TO USE THE IF STATATEMENT

IN THE FOLLOWING PROGRAM
THE USER IS TO ENTER A SINGLE CHAR O FOR OIL G FOR GAS
THE NEXT LINE IS A REAL NUMBER FOR THE COST OF A WELL
NEXT LINE THE USER A CHAR S FOR SULFUR OR CHAR N FOR NO SULFUR
IF S THIS IS FOLLOWED BY THE PERCENT OF SULFUR PRESENT

MY PROBLEM IS THTA I CAN CALC S BUT I CAN SEEM TO CALC N
THE PROBLEM APEARS TO BE IN MY IF STATEMENT BUT I CAN'T SEEM TO FIND IT:
ENCLOSED IS A COPY OF THE CODE AND THE ANSWERS I GET FOR S AND N.

/////////////////////////////////////////////////////////
//This program file is Gas or Oil
//This program will calculate the amount of gas or oil in a well
//Program Name:  Gas or Oil calculator
//Author: Terence Bell
//Description computes the amount of gas or oil

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

double oilCost = 5.50;            //This is the cost of the oil
double gasCost = 2.20;            //This is the cost of the gas

int main ()
{

char    wellType, sulfurContent;
double  costOfWell;
double  wellVolume, sulfurPresent;
long int revenue =0;

double  profit = 0;

//Member needs to input the type of well
cout<<"Enter type of well (D=Dry, O=Oil, G=Gas)"<< endl;
cin >> wellType;

if ((wellType == 'O') || (wellType == 'G'))

{
cout << "Cost of the well" << endl;
cin  >> costOfWell;

cout<< "Enter volume found" << endl;
cin >> wellVolume;

cout<< "Enter sulfurContent (N = no sulfur, S = sulfur)"<< endl;
cin >> sulfurContent;
}
if (sulfurContent == 'S')
{
cout << "Enter Sulfur present in percent" << endl;

cin >> sulfurPresent;
}

if (wellType == 'O')
//This is the calculation of the oil content
{
revenue = oilCost * (wellVolume - (wellVolume * sulfurPresent));
cout<< "The oil revenue is \$ " << revenue <<endl;
}

if (wellType == 'G')//This is the calculation of the gas content
{

revenue = gasCost * (wellVolume - (wellVolume * sulfurPresent));
cout<< "The gas revenue is \$ " << revenue <<endl;
}

else
{
revenue = gasCost * wellVolume;
cout<< "The gas revenue is \$ " << revenue <<endl;

}

profit = revenue - costOfWell;

cout<< "Profit is \$ "  << profit << endl;

{

if (profit >= 50000)
{

cout << "It's a Gusher: " << profit << endl;
}

return 0;
}
}
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Hi tbell000,

I'll give you just 2 suggestions

1) indent your code, so that it will be clear what you're doing, and when (if the condition is true or not)
2) I've found a couple of {} that were misplaced, try with this one

/////////////////////////////////////////////////////////
//This program file is Gas or Oil
//This program will calculate the amount of gas or oil in a well
//Program Name:  Gas or Oil calculator
//Author: Terence Bell
//Description computes the amount of gas or oil

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

double oilCost = 5.50;          //This is the cost of the oil
double gasCost = 2.20;          //This is the cost of the gas

int main ()
{

char    wellType, sulfurContent;
double  costOfWell;
double  wellVolume, sulfurPresent;
long int revenue =0;

double  profit = 0;

//Member needs to input the type of well
cout<<"Enter type of well (D=Dry, O=Oil, G=Gas)"<< endl;
cin >> wellType;

if( (wellType == 'O') || (wellType == 'G') )
{
cout << "Cost of the well" << endl;
cin  >> costOfWell;

cout<< "Enter volume found" << endl;
cin >> wellVolume;

cout<< "Enter sulfurContent (N = no sulfur, S = sulfur)"<< endl;
cin >> sulfurContent;
}
if( sulfurContent == 'S' )
{
cout << "Enter Sulfur present in percent" << endl;

cin >> sulfurPresent;
}

if( wellType == 'O' ) //This is the calculation of the oil content
{
revenue = oilCost * (wellVolume - (wellVolume * sulfurPresent));
cout<< "The oil revenue is \$ " << revenue <<endl;
}

if( wellType == 'G' ) //This is the calculation of the gas content
{
revenue = gasCost * (wellVolume - (wellVolume * sulfurPresent));
cout<< "The gas revenue is \$ " << revenue <<endl;
}

else
{
revenue = gasCost * wellVolume;
cout<< "The gas revenue is \$ " << revenue <<endl;
}

profit = revenue - costOfWell;

cout<< "Profit is \$ "  << profit << endl;

if (profit >= 50000)
{
cout << "It's a Gusher: " << profit << endl;
}

return 0;
}

Cheers!
Commented:
u have misplaced { }, try to place them properly. and see if it works.
Author Commented:
STILL WILL NOT SOVLE FOR N THE PROBLEM SEEMS TO BE HERE

if( wellType == 'G' ) //This is the calculation of the gas content
{
revenue = gasCost * (wellVolume - (wellVolume * sulfurPresent));
cout<< "The gas revenue is \$ " << revenue <<endl;
}

else
{
revenue = gasCost * wellVolume;
cout<< "The gas revenue is \$ " << revenue <<endl;
Associate Director - Product EngineeringCommented:
>> I'll give you just 2 suggestions

:-) I'll give you one more. All of us can read, so STOP WRITING IN CAPS ALL THE TIME :-)

By the way, what error is it goving now?

Cheers,
Mayank.
Associate Director - Product EngineeringCommented:
>> goving now

giving now
Commented:
-----------------------
if( sulfurContent == 'S' )
{
cout << "Enter Sulfur present in percent" << endl;
cin >> sulfurPresent;
}
else {
sulfurPresent = 0;
}

Experts Exchange Solution brought to you by