Hi i encountered a problem while compiler this

if (operation != '+' || '-' || '*' || '/' )
{
    cout << " Incorrect operation" <<endl ;
    system ("calculator.exe") ;
}

I am trying to use system() to launch calculator.exe. I have used this method before, here's the old code.

if (repeat = 1)
    {
    system("parent.exe");
    }

This is the error:

error: 'system' was not declared in this scope|

Make sure you have the header <iostream> and I'm pretty sure its calc.exe not calculator.exe unless that is the name of your program.

Also if (operation != '+' || '-' || '*' || '/' ) Does not do what you think it will. You want to have if( operation != '+' || operation != '-' || operation != '*' || operation != '/' ) and if( repeat = 1 ) Should be if( repeat == 1 ) = is for assigning
== is for comparing

Edited 6 Years Ago by sfuo: added more information

i already included iostream. lol i havent seen johnny bravo in years

Edited 6 Years Ago by marvolo1300: n/a

I fixed my code. I forgot to include <cstdlib>

#include <cstdlib>
#include <iostream>
#include "string.h"
        if (operation != '+' || '-' || '*' || '/' )
      {
      cout << " Incorrect operation" <<endl ;
      system ("calculator.exe") ;
      }

Don't use #include "string.h" use <cstring> for the c-string library and #include <string> for the c++ string library.

Also read my post above that corrects your if statement because that will compile but it will be true no matter what.

Edit: you need to either have using namespace std; up with your includes or using std::cout, using std::endl or just type std::cout / std::endl every time you want to use those functions.

Edited 6 Years Ago by sfuo: n/a

What is the difference between "string.h" and <c-string>? My compiler recognizes both

"string.h" is for c and <cstring> is for C++.

Since you can use C code in C++ you can get away with using "string.h" but you should use <cstring> because you might run into problems.

Same thing goes with <cstdlib> (this is correct) because it can be used as "stdlib.h" (c version) and "iostream.h".

system() is for windows only and anything that you input into that function can be inputted into the command prompt window (type cmd in run).

I don't know any php but I'm 99% sure system() is not equivalent to include in php.

Look at the file cstring and you will find out for yourself what the difference between it and string.h is. My compiler just includes string.h in cstring an them does the using statements for each of the functions

Honestly now -- how difficult is it for you to look at the file cstring and find out the answers to your question yourself???

Edited 6 Years Ago by Ancient Dragon: n/a

This question has already been answered. Start a new discussion instead.