Thread: Newbie question (Please be kind)

  1. #16
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by comwiz
    Yeah, but is only a quarter of the year. I go to a good school on Long Island. They keep there prioritys straight.
    Oh well, when the hell did English make any sense anyway?

    Code:
    if ( cleaning = 'Y' || 'y')
    I don't think it was mentioned, but relook at that line.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  2. #17
    I Write C++ Apps, Sue Me.
    Join Date
    Feb 2006
    Location
    In My Computer
    Posts
    44
    No, You need spelling. What if you spell "red" wrong and your page comes out purple? Oh NO!

  3. #18
    I Write C++ Apps, Sue Me.
    Join Date
    Feb 2006
    Location
    In My Computer
    Posts
    44
    but it is only for a quarter.

  4. #19
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Quote Originally Posted by Dae
    Code:
    if ( cleaning = 'Y' || 'y')
    I don't think it was mentioned, but relook at that line.
    It was.
    Sent from my iPadŽ

  5. #20
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    There is an edit button.

    He was being sarcastic (see my quote).

    ++postcount;

    Edit: Oh, I see Sly. >.<
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  6. #21
    Registered User
    Join Date
    Jan 2006
    Posts
    27
    Quote Originally Posted by SlyMaelstrom
    You didn't fix your second if statement. Not to mention the fact that your second if statement doesn't check your dataOk variable. Basically making your first if statement pointless.
    OK, how would I check my dataOk variable?

  7. #22
    Registered User
    Join Date
    Mar 2002
    Posts
    203
    Code:
    if (dataOK)

  8. #23
    Registered User
    Join Date
    Jan 2006
    Posts
    27


    Code:
    #include <iostream>
    
    using namespace std;
    
    int main ()
    {
        string name;  //input variaable for patient's name
        string::size_type namlen; // used for determining string size
        char xray;  //input variable for x-ray
        char cavity;  //input variable for cavity filling
        char cleaning;  //input variable for cleaning
        float xbill;  //input variable for xray bill
        float cavbill;  //input variable for cavity filling bill
        float cbill;  //input variable for cleaning bill
        float totalbill; // sum of all services performed
        bool dataOk; // True if data is correct
        
        // Prompt for patient's name and services performed
        cout << "Enter patient's name: ";  
        getline (cin, name);
           
        cout << " Was cleaning performed? (Y or y = yes, N or n = no): "; 
        cin >> cleaning;
        
        cout << " Was an x-ray performed? (Y or y = yes, N or n = no): ";
        cin >> xray;
        
        cout << " Was a cavity filling performed? (Y or y = yes, N or n = no): ";
        cin >> cavity;
        
       // Testing section
        
        namlen = name.length();
        
        if (namlen < 4) // make sure a name is entered
        {  
           cout << "Must input name."; // if no name over 4 characters, display this
           return 1;  // end program
    }
        // Testing section for services   
        if (cleaning == 'Y' || cleaning == 'y' || cleaning == 'N' || cleaning ==  'n')
           dataOk = true;
        else
           dataOk = false;
            
        if (xray == 'Y' || xray == 'y' || xray == 'N' || xray ==  'n')
           dataOk = true;
        else
           dataOk = false;
       
        if (cavity == 'Y' || cavity == 'y' || cavity == 'N' || cavity ==  'n')
           dataOk = true;
        else
           dataOk = false;
        
        if ( dataOk) // if above is found true, move on to next part
        {    
       // Assigning values to billing
        
        if ( xray == 'Y'||'y') //if the input for xray was "Y" or "y" assign 200.00 to xbill
           xbill = 200.00;
        else
           xbill = 0.00;
            
        if ( cleaning == 'Y' || 'y') //if the input for xray was "Y" or "y" assign 50.00 to cbill
           cbill = 50.00;
        else 
           cbill = 0.00;
        
        if ( cavity == 'Y' || 'y') //if the input for xray was "Y" or "y" assign 150.00 to cavbill
           cavbill = 150.00;
        else
           cavbill = 0.00;
        }
        else  //if the input is not a "Y", "y", "N", or "n"
        {
            cout << "Must answer Y or y or N or n to all questions."; 
            return 2;
        }   
        totalbill = xbill + cbill + cavbill; //total bill
        
        // display output
        ;cout << "Patient's name " << name;  
        
        ;cout << "Cleaning Charge is  " << cbill; 
        
        ;cout << "Cavity filling charge is  " << cavbill;  
        
        ;cout << "X-ray charge is  " << xbill; 
        
        ;cout << "Total bill for services is: " << totalbill; 
        
        return 0;

    }


    OK, this is my entire program. The good news is that at this point if the wrong type of data is entered it stops, the bad it doesn't assign values based on imputs. any ideas?

  9. #24
    Registered User
    Join Date
    Mar 2002
    Posts
    203
    look at // Testing section for services
    and see what is different in // Assigning values to billing

  10. #25
    Registered User
    Join Date
    Jan 2006
    Posts
    27
    Quote Originally Posted by Syneris
    look at // Testing section for services
    and see what is different in // Assigning values to billing

    Aiya!!! Thank you so much!!

  11. #26
    Registered User
    Join Date
    Jan 2006
    Posts
    27
    I do have one more question. My output screen has all the information running together, when i'd rather have it list line by line. how do i get that?

  12. #27
    Moderately Rabid Decrypt's Avatar
    Join Date
    Feb 2005
    Location
    Milwaukee, WI, USA
    Posts
    300
    To create a new line, you have two choices (that I know of):

    The newline character '\n', which creates a new line, or endl, which creates a new line and flushes the output buffer.

    Example:
    Code:
    cout << "stuff";
    cout << "new line\n";
    cout << new line << endl;
    Output
    Code:
    stuffnew line
    new line
    There is a difference between tedious and difficult.

  13. #28
    Registered User
    Join Date
    Mar 2002
    Posts
    203
    Newline

    And there is a problem with your dataOK in // Testing section for services
    I could enter any invalid answer for the first 2 questions. If I answer yes to the 3rd then the bill would be 150. If i answer no to the 3rd then my bill would be 0.

    Can loops be used?

  14. #29
    Registered User
    Join Date
    Jan 2006
    Posts
    27
    Quote Originally Posted by Syneris
    Newline

    And there is a problem with your dataOK in // Testing section for services
    I could enter any invalid answer for the first 2 questions. If I answer yes to the 3rd then the bill would be 150. If i answer no to the 3rd then my bill would be 0.

    Can loops be used?
    No loops can't be used. Loops is in our next chapter though. Do you have any ideas? Keep in mind this is a beginning programming class.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Newbie question
    By TimL in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2008, 04:43 AM
  2. Newbie with Very Newbie Question
    By Jedi_Mediator in forum C++ Programming
    Replies: 18
    Last Post: 07-01-2008, 08:00 AM
  3. newbie: array question :(
    By cstudent in forum C Programming
    Replies: 2
    Last Post: 04-09-2008, 06:46 AM
  4. Total Newbie Question
    By Kid A in forum C++ Programming
    Replies: 4
    Last Post: 06-22-2006, 05:36 AM
  5. very newbie question: how to copy files
    By webwesen in forum C Programming
    Replies: 26
    Last Post: 04-25-2002, 03:01 PM