C ++ Visual Studio

0

Hello, I am a beginner in Visual Studio. I have recently installed and I am trying out C ++ programs starting with simple programs, but the same program that ran perfectly in Geany appears with several errors in VS2015.

Example (I got some code on the internet)

#include <iostream>
using namespace std;

int main() {

int custo;
cin >> custo;
if (custo <= 20000)
    cout << (custo * 1.05);
if (custo > 20000 and custo <= 40000)
    cout << (custo * 1.1) * 1.3;
if (custo > 40000)
    cout << (custo * 1.15) * 1.45;
return 0;

The same, it ran perfectly in Geany on windows but in VS it presented the following error.

  

1> ------ Compilation started: Project: ConsoleApplication4,   Configuration: Debug Win32 ------ 1> Source1.cpp   1 > c: \ users \ such \ documents \ visual studio   2017 \ projects \ consoleapplication4 \ consoleapplication4 \ source1.cpp (10):   error C2146: syntax error: ')' missing before the identifier 'and'   1 > c: \ users \ such \ documents \ visual studio   2017 \ projects \ consoleapplication4 \ consoleapplication4 \ source1.cpp (10):   error C2065: 'and': identifier not declared   1 > c: \ users \ such \ documents \ visual studio   2017 \ projects \ consoleapplication4 \ consoleapplication4 \ source1.cpp (10):   error C2146: syntax error: ';' missing before identifier   'cost' 1> c: \ users \ such \ documents \ visual studio   2017 \ projects \ consoleapplication4 \ consoleapplication4 \ source1.cpp (10):   error C2059: syntax error: ')' 1> c: \ users \ such \ documents \ visual   studio   2017 \ projects \ consoleapplication4 \ consoleapplication4 \ source1.cpp (11):   error C2146: syntax error: ';' missing before identifier   'cout' 1> c: \ users \ such \ documents \ visual studio   2017 \ projects \ consoleapplication4 \ consoleapplication4 \ source1.cpp (10):   warning C4552: '< =': operator has no effect; expected operator with   side effect 1> Build project ready   "ConsoleApplication4.vcxproj" - FAIL.   ========== Compile: 0 Successfully, 1 Failed, 0 Updated, 0 Ignored> ==========

I was able to get some code errors but one still remained.

  

error C3861: 'and': identifier not found

I tried to use & & and it still did not work. Can someone help me? Many projects that ran perfectly in other IDEs did not work in VS.

    
asked by anonymous 18.05.2017 / 03:59

2 answers

1

You need to include the header "iso646.h":

#include <iso646.h>

link

    
18.05.2017 / 13:08
-1

try to replace the and operator with && . Example:

if (custo > 20000 && custo <= 40000) {
   ....
}
    
17.09.2018 / 19:18