CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2009
    Posts
    2

    Need help with fixing C++ code?

    Ok, here's the thing. I want to have a program that tells the user to enter the height and width of a poster.

    Then i want it to (based on the user entered numbers) to tell the user to use A4, A3, A2 or A1 paper. Must reflect portrait and landscape view.

    I'm new at C++, and so i want you to tell me what is wrong with the code I have so far, and show me how you fixed it (if you fixed it for me) or tell how to do it on my own.

    I only want to use what I know so far for the code, so nothing for advanced C++ please .

    Here is the code i have so far:

    ______

    #include <iostream>
    using namespace std;

    int main()
    {
    int pos_wid, pos_hei;

    cout << "Enter the dimensions of the poster in mm: " << endl;
    cin >> pos_wid >> pos_hei;

    if (pos_wid => 210 && pos_hei <= 297) || (pos_wid <= 297 && pos_hei => 210)
    {
    cout << "Use A4" << endl;
    }
    else if (pos_wid => 297 && pos_hei <= 420) || (pos_wid <= 420 && pos_hei => 297)
    {
    cout << "Use A3" << endl;
    }
    else if (pos_wid => 420 && pos_hei <= 594) || (pos_wid <= 594 && pos_hei => 420)
    {
    cout << "Use A2" << endl;
    }
    else if (pos_wid => 594 && pos_hei <= 810) || (pos_wid <= 810 && pos_hei => 594)
    {
    cout << "Use A1" << endl;
    }
    else
    {
    cout << "Not in stock" << endl;
    }
    system("pause>null");
    }

    ______
    Oh and please don't laugh if you find a lot of errors , like I said i'm new.

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: Need help with fixing C++ code?

    Did it compile?
    Did you run it?
    Did it work?

  3. #3
    Join Date
    Mar 2009
    Posts
    2

    Re: Need help with fixing C++ code?

    Quote Originally Posted by GCDEF View Post
    Did it compile?
    Did you run it?
    Did it work?
    No.

    Couldn't didn't work.

    No.

  4. #4
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: Need help with fixing C++ code?

    Would be a good idea to tell what the compiler thinks about your code.
    Anyway there is no operator =>. use >= instead.
    Kurt

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: Need help with fixing C++ code?

    => should be >=

    For help with compiling problems, it's best to tell us what the errors are that you're getting.

    Also, please use code tags.

  6. #6
    Join Date
    Feb 2002
    Posts
    3,788

    Re: Need help with fixing C++ code?

    i only corrected the first if.
    Code:
    if (((pos_wid >= 210) && (pos_hei <= 297)) || ((pos_wid <= 420) && (pos_hei >= 297)))
    { 
    	cout << "Use A4" << endl;
    }
    Last edited by Alin; March 20th, 2009 at 01:39 PM.

  7. #7
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: Need help with fixing C++ code?

    Looking at it again, I think you want <= 210, not >=.

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

Featured