C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Newbie 2 First Grade!

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
PerritoPerron
Guest





PostPosted: Wed Jul 30, 2003 1:10 am    Post subject: Newbie 2 First Grade! Reply with quote



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...


Back to top
Alf P. Steinbach
Guest





PostPosted: Wed Jul 30, 2003 1:30 am    Post subject: Re: Newbie 2 First Grade! Reply with quote



On Wed, 30 Jul 2003 01:10:48 GMT, "PerritoPerron" <peter (AT) aol (DOT) tv> wrote:

Quote:
void main(){

'main' must have result type 'int'.

Some compilers erronously accept 'void'.


Quote:
char Mybuffer[32];

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


Quote:
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.



Quote:
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...


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.