TripleX - If/Else syntax errors. Help!

I was trying to do the If/Else section of this course, but I started getting syntax errors with this code.

// TripleX is a number game based in the Star Wars Universe.

#include

int main()

// Sending welcome messages to the console.

std::cout << "You are an Imperial Security Bureau Agent trying to break into a Banking Clan vault...";

std::cout << std::endl;

std::cout << "You must enter the correct digits to continue..." << std::endl;

// Declare 3 number code.

const int CodeA = 1;

const int CodeB = 9;

const int CodeC = 7;

const int CodeSum = CodeA + CodeB + CodeC;

const int CodeProduct = CodeA * CodeB * CodeC;



// Print CodeSum and CodeProduct to terminal.

std::cout << std::endl;

std::cout << "| There are 3 numbers in the code." << std::endl;

std::cout << "| The code adds up to: " << CodeSum << std::endl;

std::cout << "| The code multiplies to give: " << CodeProduct << std::endl;

int GuessA, GuessB, GuessC;

std::cin >> GuessA;

std::cin >> GuessB;

std::cin >> GuessC;

int GuessSum = GuessA + GuessB + GuessC;

int GuessProduct = GuessA * GuessB * GuessC;

if (GuessSum == CodeSum && GuessProduct == CodeProduct)

{

    std::cout << "| You've broken in! You win!";

}

else

{

    std::cout << "| You've been seen! Run!";

}



return 0;

Errors:

TripleX.cpp(21): error C2143: syntax error: missing ‘;’ before ‘<<’
TripleX.cpp(21): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
TripleX.cpp(21): error C2371: ‘std::cout’: redefinition; different basic types
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\iostream(34): note: see declaration
of ‘std::cout’
TripleX.cpp(22): error C2143: syntax error: missing ‘;’ before ‘<<’
TripleX.cpp(22): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
TripleX.cpp(22): error C2371: ‘std::cout’: redefinition; different basic types
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\iostream(34): note: see declaration
of ‘std::cout’
TripleX.cpp(23): error C2143: syntax error: missing ‘;’ before ‘<<’
TripleX.cpp(23): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
TripleX.cpp(23): error C2371: ‘std::cout’: redefinition; different basic types
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\iostream(34): note: see declaration
of ‘std::cout’
TripleX.cpp(24): error C2143: syntax error: missing ‘;’ before ‘<<’
TripleX.cpp(24): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
TripleX.cpp(24): error C2371: ‘std::cout’: redefinition; different basic types
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\iostream(34): note: see declaration
of ‘std::cout’
TripleX.cpp(27): error C2143: syntax error: missing ‘;’ before ‘>>’
TripleX.cpp(27): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
TripleX.cpp(27): error C2371: ‘std::cin’: redefinition; different basic types
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\iostream(33): note: see declaration
of ‘std::cin’
TripleX.cpp(28): error C2143: syntax error: missing ‘;’ before ‘>>’
TripleX.cpp(28): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
TripleX.cpp(28): error C2371: ‘std::cin’: redefinition; different basic types
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\iostream(33): note: see declaration
of ‘std::cin’
TripleX.cpp(29): error C2143: syntax error: missing ‘;’ before ‘>>’
TripleX.cpp(29): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
TripleX.cpp(29): error C2371: ‘std::cin’: redefinition; different basic types
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\iostream(33): note: see declaration
of ‘std::cin’
TripleX.cpp(34): error C2059: syntax error: ‘if’
TripleX.cpp(35): error C2143: syntax error: missing ‘;’ before ‘{’
TripleX.cpp(35): error C2447: ‘{’: missing function header (old-style formal list?)
TripleX.cpp(39): error C2059: syntax error: ‘else’
TripleX.cpp(40): error C2143: syntax error: missing ‘;’ before ‘{’
TripleX.cpp(40): error C2447: ‘{’: missing function header (old-style formal list?)
TripleX.cpp(46): error C2059: syntax error: ‘return’

1 Like

First of all, your code runs fine.
Second of all, your code does not run fine on your PC, because if that’s the exact code you are running, then there are issues.

  1. You have an empty #include
  2. Your main method is not included inside a code block (inside curly brackets { }), meaning the compiler will show all these errors you see in every line of the code.

I don’t know how in the name of sanity I deleted that and didn’t notice it.
Thanks.
facepalm

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms