Help Me!!!!!!!!!

This is a discussion on Help Me!!!!!!!!! within the C++ Programming forums, part of the General Programming Boards category; ok im new 2 c++ and im trying to make a basic program that stats push q to square s ...

  1. #1
    Registered User Prodigy's Avatar
    Join Date
    May 2002
    Posts
    25

    Help Me!!!!!!!!!

    ok im new 2 c++ and im trying to make a basic program that stats
    push q to square s subtract a 2 add d 2 divide
    so what do i do after i type this
    if its a lot of lines to do this if u wouldnt mind writing it or just say its too many lines
    (if your too lazy ad dont wat to help me) >:|
    --------------------------------------------------------------------------
    #include < iostream.h>
    int main ()
    {
    int x,q,s,a,d;
    cout << "x=square d=divide a=add s=subtract q=square";
    ----------------------------------------------------------------------------
    now what do i say
    cin >> x;
    cin >> d;
    ....... and so on
    ---------------------------------------------------------------------------
    or do i skip that and say
    if (x)
    bla bla
    if (q)
    bla bla
    ........... and so on
    ----------------------------------------------------------------------------

    Or am i just totally off track

    i would really like it if u helped me out.......

    thx
    And the cows moo...
    AIM:ProdigyCpp
    E-Mail:ProdigyMan911@aol.com
    If you like my avatar plz dont copy it go to:
    http://www.dragid.com/

  2. #2
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Lightbulb Like this...

    I will not post it all, but I will post what you want:

    int main()
    {
    char choice;

    cout << "x=square d=divide a=add s=subtract";
    cin >> choice;

    if((choice == 'x') || (choice == 'X'))
    {
    // Square
    }
    if((choice == 'd') || (choice == 'D'))
    {
    // Divide
    }
    if((choice == 'a') || (choice == 'A'))
    {
    // Add
    }
    if((choice == 's') || (choice == 'S'))
    {
    // Subtract
    }

    return 0;
    }

    This checks to see if they do uppercase OR lowercase
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    if((choice == 'x') || (choice == 'X'))
    {
    // Square
    }
    if((choice == 'd') || (choice == 'D'))
    {
    // Divide
    }
    if((choice == 'a') || (choice == 'A'))
    {
    // Add
    }
    if((choice == 's') || (choice == 'S'))
    {
    // Subtract
    }
    This is bad style. The evaluation process continues even if the first one was true...also, instead of comparing both lower and uppercase, just convert the input into one or the other ( or else make a copy of it first to preserve the input)...

    And Prodigy: I think you are confusing variables with the input expected...there is no need for more than one here.


    Code:
    #include < iostream.h>
     
    int main () 
    { 
    
    char c;
    
    cout << "x=square d=divide a=add s=subtract q=square"; 
    
    cin >> c;
    
    
    c = tolower(c);
    
    
    if( c == 'x' ) 
     { 
      // Square 
     }
    else 
    if( c == 'd' ) 
     { 
      //...divide... 
     } 
    else 
    if( c == 'a' ) 
     {
       //...do addition...
     } 
    else 
    if( c == 's' )
     {
       //...do subtraction...
     } 
    else 
    if( c == 'q' )
     {
       //...do square...
     } 
     
    
    
    return 0;
    }

    ...also you could use a switch statement instead...
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    eat my shorts!
    Join Date
    Apr 2002
    Posts
    294
    ya man if u dont know how to do this
    dont do it in c++
    first go learn c it is much "user friendly",
    if u have then do the exact thing but change printf to cout<<
    and scanf to cin>> and some small things here n there

    so go learn C 1st

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21