 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
PerritoPerron Guest
|
Posted: Wed Jul 30, 2003 1:10 am Post subject: Newbie 2 First Grade! |
|
|
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
|
Posted: Wed Jul 30, 2003 1:30 am Post subject: Re: Newbie 2 First Grade! |
|
|
On Wed, 30 Jul 2003 01:10:48 GMT, "PerritoPerron" <peter (AT) aol (DOT) tv> wrote:
'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 |
|
 |
|
|
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
|
|