Thread: Gas/Oil program for class

  1. #1
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331

    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;
    
    		default:	cout<<"Bad input!\n";
    					break;
    	}
    
                    if (profitorloss >= 50000.00)
                    { 
                      cout<<"Gusher!\n"<<profitorloss<<"\n";
                    }
    
                    else:
    cout<<"Revenue for this well is "<<profitorloss<<".\n";            
    
    
    
    	return 0;
    }

  2. #2
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    lol rideordie, try to replace the tabs with spaces after you copy/paste. It makes the code easier to read
    Last edited by Hunter2; 11-04-2002 at 05:37 PM.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  3. #3
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM