Results 1 to 6 of 6

Thread: Easy Question

Hybrid View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Gig Harbor, WA; Posts: 89950
    Posts
    360

    Angry

    I have a project due today for school, and it runs ok but repeats the question 2x, what am I doing wrong????



    #include <iostream.h>
    #include <ctype.h>
    #include <string.h>

    void main()
    {

    //Declare and initialize variables
    float meShip = (float) 25.00; //Accumulator for ME
    float txShip = (float) 30.00; //Accumulator for TX
    float njShip = (float) 32.50; //Accumulator for NJ
    short meCount = 0; //Counter for ME
    short txCount = 0; //Counter for TX
    short njCount = 0; //Counter for NJ
    short errCt = 0; //Error Count
    char state[3] = "";


    while (state != "XX")
    {
    //enter input
    cout << "Enter State where items are to be shipped (ME, TX or MJ) or press XX to end: " <<endl;

    cin.getline(state, 3);
    state[3] = toupper(state[3]); //Change to upper case

    if (stricmp(state,"ME") == 0)
    { meCount = (meCount +1); }


    else if (stricmp(state, "TX") == 0)
    { txCount = (txCount +1); }


    else if (stricmp(state, "NJ") == 0)
    { njCount = (njCount +1);}


    else if (stricmp(state, "xx") == 0)
    { cout << "Number of Entries in ME: " << meCount<< " Total Amount: $" << float(meCount * meShip) << endl;

    cout << "Number of Entries in TX: " << txCount << " Total Amount: $" << float(txCount * txShip) << endl;

    cout << "Number of Entries in NJ: " << njCount << " Total Amount: $" << float(njCount * njShip) << endl;

    cout << "Number of Invalid entries: " << errCt << endl; }


    else
    errCt = (errCt +1);


    }//End While


    } //End of main

    Please help!
    Thanks!
    Lee
    Mahalo
    VB6(SP5), VC++, COBOL, Basic, JAVA
    MBA, MCSD, MCSE, A+
    Computer Forensics

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    while (state != "XX")

    you can't check string equality like that unless you use the string class.
    Harry.

    "From one thing, know ten thousand things."

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Gig Harbor, WA; Posts: 89950
    Posts
    360
    uhhm, I thought I did...
    #include <string.h>

    Or am I incorrect? I am just learning
    Mahalo
    VB6(SP5), VC++, COBOL, Basic, JAVA
    MBA, MCSD, MCSE, A+
    Computer Forensics

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Nope. Doesn't work like that .

    The string class is in a header called string:
    Code:
    #include <iostream>
    #include <string>
    
    using namespace std; // Very important!
    
    void main() {
        string x = "This is my string";
        string y = " again!";
    
        string z = x + y;
    
        z += "55";
    
        cout << z << endl;
    }
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Gig Harbor, WA; Posts: 89950
    Posts
    360
    I am not adding them, I am only checking to see if those letters were entered by the user, if so how many times were they entered
    Mahalo
    VB6(SP5), VC++, COBOL, Basic, JAVA
    MBA, MCSD, MCSE, A+
    Computer Forensics

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Gig Harbor, WA; Posts: 89950
    Posts
    360

    Talking

    Mahalo to you!
    (Thanks Dude)
    Mahalo
    VB6(SP5), VC++, COBOL, Basic, JAVA
    MBA, MCSD, MCSE, A+
    Computer Forensics

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width