Beginner Tutorial Issue

Started by
13 comments, last by MRom 9 years, 7 months ago

**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);
}
Advertisement

Rebuild all (rebuild the whole project from scratch).

What compiler?

What is the target platform?

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Rebuild all (rebuild the whole project from scratch).

What compiler?

What is the target platform?

L. Spiro

Sorry, I should've included that information.

I'm using Microsoft Visual C++ 2010 Express.

The tutorial instructed me to make a 'Win32 Console Application'. As far as the platform I'm targeting, I'm assuming it's just PC. I'm just trying to follow the tutorial.

Ctrl+Alt+F7 to rebuild all.

Right-click the project in the side pane. Press R.

Post screenshot of the window that appears.

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Ctrl+Alt+F7 to rebuild all.

Right-click the project in the side pane. Press R.

Post screenshot of the window that appears.

L. Spiro

I hope this is what you were looking for.

The project is the bold-lettered “1.11 Quiz 1”.

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

You need to add std:: before each use of cout, cin and endl.

Otherwise add

using namespace std;

after the #includes.

Your book must be rather old...

EDIT: Oh you have that already... didn't see that.

As L. Spiro says, you need to do a full rebuild.

EDIT2: You keep editing the code, making my replies seem foolish.

EDIT3: Nope, my mistake, there are 2 programs not just 1, one of them has using namespace std in each function and the other has using namespace std.

I'll get my coat ;)

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

My last reply was a hint to right-click 1.11 Quiz 1, press R, and post the screenshot again.

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

I've occasionally had issues where Rebuild all did not fix this, but deleting the Debug and Release directories worked (if they don't exist they are recreated by a build).

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

I've occasionally had issues where Rebuild all did not fix this, but deleting the Debug and Release directories worked (if they don't exist they are recreated by a build).

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

This topic is closed to new replies.

Advertisement