**Edit** Sorry for posting this topic here - I didn't see the Beginner Forum
Hey guys,
I'm almost embarrassed to be posting this but I've come to learn it's better to be embarrassed and know what went wrong than to not learn from a mistake...
Anyhow, I'm not kidding when I say I'm a beginner - I've never touched C++ till a few days ago.
I'm running through this tutorial:
http://www.learncpp.com/cpp-tutorial/111-comprehensive-quiz/
I'm working on the first quiz part 1.
When I try to complie my code I get the following error:
1>------ Build started: Project: 1.11 Quiz 1, Configuration: Debug Win32 ------
1>LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I even copied and pasted the code exactly as show in the tutorial. I've the following:
// 1.11 Quiz 1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
int ReadNumber()
{
using namespace std;
cout << "Enter a number: ";
int x;
cin >> x;
return x;
}
void WriteAnswer(int x)
{
using namespace std;
cout << "The answer is " << x << endl;
}
int main()
{
int x = ReadNumber();
int y = ReadNumber();
WriteAnswer(x+y);
return 0;
}
Can someone please explain to me what went wrong?
I've the exact same error when trying to compile another 'calculator' program which again was part of the tutorial:
#include "stdafx.h"
#include <iostream>
using namespace std;
int GetUserInput()
{
cout << "Please enter an integer: ";
int nValue;
cin >> nValue;
return nValue;
}
char GetMathematicalOperation()
{
cout << "Please enter an operator (+,-,*,or /): ";
char chOperation;
cin >> chOperation;
// What if the user enters an invalid character?
// We'll ignore this possibility for now
return chOperation;
}
int CalculateResult(int nX, char chOperation, int nY)
{
if (chOperation=='+')
return nX + nY;
if (chOperation=='-')
return nX - nY;
if (chOperation=='*')
return nX * nY;
if (chOperation=='/')
return nX / nY;
return 0;
}
void PrintResult(int nResult)
{
cout << "Your result is: " << nResult << endl;
}
int main()
{
// Get first number from user
int nInput1 = GetUserInput();
// Get mathematical operation from user
char chOperator = GetMathematicalOperation();
// Get second number from user
int nInput2 = GetUserInput();
// Calculate result
int nResult = CalculateResult(nInput1, chOperator, nInput2);
// Print result
PrintResult(nResult);
}