Jump to content
  • Advertisement
Sign in to follow this  
MRom

Beginner Tutorial Issue

This topic is 1422 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

**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

Share this post


Link to post
Share on other sites
Advertisement

Rebuild all (rebuild the whole project from scratch).

What compiler?

What is the target platform?

 

 

L. Spiro

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

 

 

L. Spiro

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!