Jump to content

  • Log In with Google      Sign In   
  • Create Account

Beginner Tutorial Issue


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
14 replies to this topic

#1 MRom   Members   -  Reputation: 143

Like
1Likes
Like

Posted 20 August 2014 - 08:04 PM

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

Edited by MRom, 20 August 2014 - 08:28 PM.


Sponsor:

#2 L. Spiro   Crossbones+   -  Reputation: 14258

Like
1Likes
Like

Posted 20 August 2014 - 09:04 PM

Rebuild all (rebuild the whole project from scratch).

What compiler?

What is the target platform?

 

 

L. Spiro


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#3 MRom   Members   -  Reputation: 143

Like
0Likes
Like

Posted 20 August 2014 - 09:22 PM

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.



#4 L. Spiro   Crossbones+   -  Reputation: 14258

Like
2Likes
Like

Posted 20 August 2014 - 09:25 PM

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


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#5 MRom   Members   -  Reputation: 143

Like
0Likes
Like

Posted 20 August 2014 - 10:03 PM

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.

Attached Thumbnails

  • Tutorial Quiz Error.png


#6 L. Spiro   Crossbones+   -  Reputation: 14258

Like
2Likes
Like

Posted 20 August 2014 - 11:05 PM

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

 

 

L. Spiro


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#7 Paradigm Shifter   Crossbones+   -  Reputation: 5435

Like
2Likes
Like

Posted 21 August 2014 - 03:03 AM

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 ;)


Edited by Paradigm Shifter, 21 August 2014 - 03:11 AM.

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

#8 L. Spiro   Crossbones+   -  Reputation: 14258

Like
1Likes
Like

Posted 21 August 2014 - 06:32 AM

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

 

 

L. Spiro


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#9 Paradigm Shifter   Crossbones+   -  Reputation: 5435

Like
0Likes
Like

Posted 21 August 2014 - 06:44 AM

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

#10 Paradigm Shifter   Crossbones+   -  Reputation: 5435

Like
0Likes
Like

Posted 21 August 2014 - 06:45 AM

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

#11 MRom   Members   -  Reputation: 143

Like
0Likes
Like

Posted 21 August 2014 - 08:04 AM

 

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

 

 

L. Spiro

 

Yes I know, sorry but I'm currently at work. I won't be home for another 9 hours.

I'll do so as soon as I've the chance, thanks again for the help.

 

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).

 

I'll try this as soon as I can and let you know the result.



#12 Iceey   Members   -  Reputation: 139

Like
1Likes
Like

Posted 21 August 2014 - 10:47 AM

I googled your problem and found a thread with possible solutions so here they are:

 

I am using Visual Studio 2010.

This happened to me when I installed .NET 4.5. Uninstall of .NET 4.5 and install of .NET 4.0 helped me and error messages disappeared.

 

Had to install VS 2010 SP1 in order to get it to work again for myself. Lame microsoft.

 

Do you have Visual Studio 2012 installed as well? If so, 2012 stomps your 2010 IDE, possibly because of compatibility issues with .NET 4.5 and .NET 4.0.

See http://social.msdn.microsoft.com/Forums/da-DK/vssetup/thread/d10adba0-e082-494a-bb16-2bfc039faa80

 

I had this issue and I solved it with this thread

disable incremental linking, by going to

Project Properties
-> Configuration Properties
-> Linker (General)
-> Enable Incremental Linking -> "No (/INCREMENTAL:NO)"

I'd try installing the Service Pack first. Here the link: click me, please


Edited by Iceey, 21 August 2014 - 10:49 AM.


#13 Serapth   Crossbones+   -  Reputation: 5755

Like
1Likes
Like

Posted 21 August 2014 - 11:07 AM

What Iceey said is bang on.  It's a bug, sorta.  Actually it's a prior version of Visual Studio being broken by later updates.

 

 

His suggestion will fix it, simply run the Visual Studio service pack and you are off to the races.

 

 

... welcome to the fun world of C++. ;)  Nasty first bug to encounter I will admit.



#14 Magogan   Members   -  Reputation: 206

Like
1Likes
Like

Posted 22 August 2014 - 05:28 AM

Just google the error code if you don't know how to fix it. You will often find a solution for it. In this case it is the first result: https://www.google.com/search?q=lnk1123

#15 MRom   Members   -  Reputation: 143

Like
0Likes
Like

Posted 26 August 2014 - 08:58 AM

Sorry, forgot to update. I've been real busy as of late.

 

You guys were 100% correct, my 'Visual Studio' was out of date and it was a bug with the software, not my program. As soon as I updated it, it worked just fine. I've upgraded to Visual Studio 2013 to HOPEFULLY avoid these issues down the road.

 

A little fustrating but I'm a little relieved as well.

 

Thanks again to everyone who took the time to reply, it was greatly appreciated.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS