Solved

I'M CONFUSED ON HOW TO USE THE IF STATATEMENT

Posted on 2003-12-11
7
228 Views
Last Modified: 2010-04-02
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;
}
}
0
Comment
Question by:tbell000
7 Comments
 
LVL 9

Expert Comment

by:tinchos
ID: 9925512
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!
0
 
LVL 24

Expert Comment

by:shivsa
ID: 9925579
u have misplaced { }, try to place them properly. and see if it works.
0
 

Author Comment

by:tbell000
ID: 9925757
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;        
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 30

Expert Comment

by:Mayank S
ID: 9926128
>> 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.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 9926137
>> goving now

giving now
0
 
LVL 24

Accepted Solution

by:
shivsa earned 500 total points
ID: 9926194
Just add this else statement after u check about sulfer content.
-----------------------
 if( sulfurContent == 'S' )
     {
          cout << "Enter Sulfur present in percent" << endl;
          cin >> sulfurPresent;
     }
else {
           sulfurPresent = 0;
    }
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 9926374
Oh right.... its not Java :-) the value won't be initialized by itself to 0.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
c++ how to tell if the progra is ctl or mfc atl ect 6 64
sorting efficency of sorting algorithm 30 103
Dialogbox API leak? 18 81
Error C2678: binary '!=': no operator found... 4 42
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now