Need help with bridgescoring program! Please Help!
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Need help with bridgescoring program! Please Help!

  1. #1
    Join Date
    Feb 2009
    Posts
    11

    Need help with bridgescoring program! Please Help!

    Okay, so I am having a few problems with my computer science lab. Below is what I have so far. I am almost positive that the equations are correct, but for some reason I keep getting a different answer than the cs labs example program. So obviously something is wrong. Could you please help me find the problem and solve it?

    Here is the lab write-up for reference.
    http://www.cs.utk.edu/~cs102/labs/labsholder/lab4.html

    My imput for my program and the example program has been this.

    N
    2H
    Y
    10

    Now the difference is that my output is this.

    2 H by North, making 10 for 280 points

    And the example programs output is this.

    2 H by North, making 4 for 170 points

    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    bool isGame (int, string);
    
    int main()
    {
    string trump;
    int score, contract, numTricks;
    char winner, vuln;
    bool win = true;
    
    cout << "Who won the bidding? " "(N/S/E/W): ";
    cin >> winner;
    
    if(winner!='N' && winner!='S' && winner!='E'&& winner !='W')
    {
    cout << "Directions must be N, S, E, or W.\n";
    return 0;
    }
    
    
    cout << "What won the contract? " "(Such as 2 H or 3 NT): ";
    
    cin >> contract;
    cin >> trump;
    
    if (trump!="NT" && trump!="S" && trump!="A" && trump!="D" && trump!="H"){
    
    cout << "The contract's suit must be NT, S, H, D or A.\n";
    return 0;
    }
    
    if(contract > 7||contract < 1){
    cout << "Contract is wrong.\n";
    return 0;
    }
    
    cout << "Was the partnership vulnerable? (Y/N): ";
    cin >> vuln;
    
    if(vuln != 'Y' && vuln != 'N'){
    cout << "Vulnerability must be Y or N.";
    return 0;
    }
    
    //check if we won enough tricks
    
    cout << "How many tricks were taken? ";
    cin >> numTricks;
    
    
    if((contract+6) > numTricks)
    {
    win = false; // we lost so update our win boolean
    if (vuln == 'Y')
    {
    score= -100*((contract+6)-numTricks);// do calculations for this case
    }
    else
    {
    score= -50*((contract+6)-numTricks);// do calcs for no case
    
    }
    }
    else // we won calculate score for winning
    {
    if (vuln == 'N')
    {
    score= 20*(numTricks-6);
    }
    
    else (trump == "S" || trump == "H"|| trump == "A" || trump == "D");{//Won Enough)
    score= 30*(numTricks-6);
    }
    
    if (trump=="NT");{
    score=20*((numTricks-6)+(10));
    }
    }
    
    cout << contract << " " << trump << " by";
    
    if ( winner == 'N') {cout << " North, ";}
    if ( winner == 'S') {cout << " South, ";}
    if ( winner == 'W') {cout << " West, ";}
    if ( winner == 'E') {cout << " East, ";}
    
    if (win)
    {
    cout << "making";
    }
    else
    {
    cout << " down";
    }
    
    cout << " " << numTricks <<" for" << " " << score << " " << "points\n";
    
    return 0;
    }
    Last edited by jladd5; February 10th, 2009 at 03:06 AM.

  2. #2
    Join Date
    Jan 2004
    Location
    Düsseldorf, Germany
    Posts
    2,401

    Re: Need help with bridgescoring program! Please Help!

    Please properly indent your code and post again. Without indentation the logic of your code is very hard to follow.

    Check the syntax of the following line:
    Code:
    else (trump == "S" || trump == "H"|| trump == "A" || trump == "D");{//Won Enough)
    It certainly does not do what you intended it to.
    More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf

    Premature optimization is the root of all evil --Donald E. Knuth


    Please read Information on posting before posting, especially the info on using [code] tags.

  3. #3
    Join Date
    Feb 2009
    Posts
    11

    Re: Need help with bridgescoring program! Please Help!

    Here it is properly indented.
    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    bool isGame (int, string);
    
    int main()
    {
        string trump;
        int score, contract, numTricks;
        char winner, vuln;
        bool win = true;
    
        cout << "Who won the bidding? " "(N/S/E/W): ";
        cin >> winner;
    
        if(winner!='N' && winner!='S' && winner!='E'&& winner !='W')
    
        {
            cout <<  "Directions must be N, S, E, or W.\n";
            return 0;
    
    
    
    
    
            cout << "What won the contract? " "(Such as 2 H or 3 NT): ";
    
    
            cin >> contract;
    
            cin >> trump;
    
            if (trump!="NT" && trump!="S" && trump!="A" && trump!="D" && trump!="H"){
    
                cout << "The contract's suit must be NT, S, H, D or A.\n";
    
                return 0;
        }
    
    
            if(contract > 7||contract < 1){
    
                cout << "Contract is wrong.\n";
    
                return 0;
            }
    
    
            cout << "Was the partnership vulnerable? (Y/N): ";
       cin >> vuln;
    
    
            if(vuln != 'Y' && vuln != 'N'){
    
                cout << "Vulnerability must be Y or N.";
    
                return 0;
            }
    
        //check if we won enough tricks
    
    
            cout << "How many tricks were taken? ";
    
            cin >> numTricks;
    
    
    
            if((contract+6) > numTricks)
            {
    
                win = false; // we lost so update our win boolean
            }
    
            if (vuln == 'Y')
            {
    
                score= -100*((contract+6)-numTricks);// do calculations for this case
            }
    
            else
            {
                score= -50*((contract+6)-numTricks);// do calcs for no case
    
            }
      
    
        else  //  we won calculate score for winning
    
        {
            if (vuln == 'N')
            {
                score= 20*(numTricks-6);
            }
    
            else (trump == "S" || trump == "H"|| trump == "A" || trump == "D");{//Won Enough)
                score= 30*(numTricks-6);
                }
        if (trump=="NT");{
                score=20*((numTricks-6)+(10));
                }
    
    
    
        }
    
        cout << contract << " " << trump << " by";
    
        if ( winner == 'N') {cout << " North, ";}
        if ( winner == 'S') {cout << " South, ";}
        if ( winner == 'W') {cout << " West, ";}
        if ( winner == 'E') {cout << " East, ";}
    
    
    
        if (win)
        {
            cout << "making";
        }
        else
        {
            cout << " down";
        }
    
        cout << " " << numTricks <<" for" << " " << score << " " << "points\n";
    
        return 0;
    }

  4. #4
    Join Date
    Jan 2004
    Location
    Düsseldorf, Germany
    Posts
    2,401

    Re: Need help with bridgescoring program! Please Help!

    Did you look at the line I quoted?

    Besides, I would not call this "properly" indented.
    More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf

    Premature optimization is the root of all evil --Donald E. Knuth


    Please read Information on posting before posting, especially the info on using [code] tags.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center