C++ Visual Studio

Asked

Viewed 868 times

0

Hello, I’m very beginner in Visual Studio.I installed recently and I’m trying programs in c++ starting with simple programs but a same program that ran perfectly in Geany appears with several errors in VS2015.

Example ( I picked up any 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, ran perfectly on Geany in windows but on VS presented the following error.

1>------ Compilation started: Project: Consoleapplication4, Settings: Debug Win32 ------ 1>Origem1.cpp 1>c: users Tales Documents visual studio 2017 Projects consoleapplication4 consoleapplication4 origem1.cpp(10): error C2146: syntax error: ')' missing before identifier 'and' 1>c: users Tales Documents visual studio 2017 Projects consoleapplication4 consoleapplication4 origem1.cpp(10): error C2065: 'and': undeclared identifier 1>c: users Tales Documents visual studio 2017 Projects consoleapplication4 consoleapplication4 origem1.cpp(10): error C2146: syntax error: ';' missing before identifier 'cost' 1>c: users Tales Documents visual studio 2017 Projects consoleapplication4 consoleapplication4 origem1.cpp(10): error C2059: syntax error: ')' 1>c: users Tales Documents visual studio 2017 Projects consoleapplication4 consoleapplication4 origem1.cpp(11): error C2146: syntax error: ';' missing before identifier 'Cout' 1>c: users Tales Documents visual studio 2017 Projects consoleapplication4 consoleapplication4 origem1.cpp(10): Warning C4552: '<=': operator has no effect; expected operator with side effect 1>Ready build project "Consoleapplication4.vcxproj" -- FAULT. ========== Compile: 0 successful, 1 failed, 0 updated, 0 ignored >==========

I managed to get some errors out of the code but one still remained.

error C3861: 'and': identifier not found

tried to use && and still didn’t work. Can anyone help me? Many projects that ran perfectly on other Ides didn’t work on VS.

2 answers

1

-1

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

if (custo > 20000 && custo <= 40000) {
   ....
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.