Newbie 2 First Grade!

Discussion in 'C++' started by PerritoPerron, Jul 30, 2003.

  1. void main(){

    char Mybuffer[32];
    I got this input from user

    1+2*3
    from this line
    cin.getline(Mybuffer, 32 '\n');

    My question is how can I compute the result???
    Need a little help here u know what I mean...

    }

    Thanks Fellas...
     
    PerritoPerron, Jul 30, 2003
    #1
    1. Advertising

  2. On Wed, 30 Jul 2003 01:10:48 GMT, "PerritoPerron" <> wrote:

    >void main(){


    'main' must have result type 'int'.

    Some compilers erronously accept 'void'.


    >char Mybuffer[32];


    Use 'std::string', what you have is a buffer that will likely
    overflow.


    >I got this input from user
    >
    >1+2*3
    >from this line
    >cin.getline(Mybuffer, 32 '\n');


    No you did not. That won't compile.



    >My question is how can I compute the result???
    >Need a little help here u know what I mean...


    As Greg P. have answered, check out Bjarne Stroustrup's TCPPPL
    book for ideas on how to do that in C++.

    But at your current level consider using an interpreted language,
    e.g., JScript in Windows,


    ==================================================================
    // Tab = indent = 4
    // A _very_ primitive calculator.
    // Note: WScript is not part of JScript but is provided by the WSH environment.

    var expression;
    var stdout = WScript.StdOut;
    var stdin = WScript.StdIn;

    stdout.Write( "? " );
    expression = stdin.ReadLine();
    stdout.WriteLine( eval( expression ).toString() );
    ==================================================================


    or VBScript (this also in Windows)


    ==================================================================
    ' Tab = indent = 4
    ' A _very_ primitive calculator.
    ' Note: WScript is not part of VBScript but is provided by the WSH environment.

    option explicit

    dim expression, stdout, stdin

    set stdout = WScript.StdOut
    set stdin = WScript.StdIn

    stdout.Write "? "
    expression = stdin.ReadLine
    stdout.WriteLine Replace( Eval( expression ), ",", "." )
    ==================================================================


    or Perl (more system-independent)


    ==================================================================
    # Tab = indent = 4
    # A _very_ primitive calculator.

    use strict;

    my $expression;

    print "? ";
    $expression = <STDIN>;
    print eval $expression;
    ==================================================================


    Hope this helps...
     
    Alf P. Steinbach, Jul 30, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt Clement
    Replies:
    5
    Views:
    800
  2. Razvan
    Replies:
    1
    Views:
    3,080
    Razvan
    Nov 22, 2004
  3. Henry

    Grade Program Question

    Henry, Sep 8, 2003, in forum: C Programming
    Replies:
    35
    Views:
    1,069
  4. tea-jay

    grade multiple-choice exam

    tea-jay, Apr 17, 2007, in forum: C++
    Replies:
    7
    Views:
    559
    osmium
    Apr 19, 2007
  5. cnb
    Replies:
    1
    Views:
    723
    George Sakkis
    Aug 29, 2008
Loading...

Share This Page