0

Hello!! I have started learning c++ and it has been a real sucess until now. My codes that worked before and those that im trying to use now, doesn't work.. I get a compiler error... Here is the code and the error: // tutorialearning.cpp : Defines the entry point for the console application.

#include <iostream>
#include <stdafx.h>


int doubleNumber(int x)
{
	return 2 * x;
}

int main()
{   
        using namespace std;
	cout << "Number to double: " << endl;
	cin >> x;
	cout << "Doubled number: " << doublenumber(x) << endl;
	return 0;
}

And im getting this in the compiler when i try to build:

1>------ Build started: Project: tutorialearning, Configuration: Debug Win32 ------
1>Compiling...
1>tutorialearning.cpp
1>d:\c++projects\tutorialearning\tutorialearning\tutorialearning.cpp(4) : warning C4627: '#include <iostream>': skipped when looking for precompiled header use
1>        Add directive to 'stdafx.h' or rebuild precompiled header
1>d:\c++projects\tutorialearning\tutorialearning\tutorialearning.cpp(14) : error C2871: 'std' : a namespace with this name does not exist
1>d:\c++projects\tutorialearning\tutorialearning\tutorialearning.cpp(15) : error C2065: 'cout' : undeclared identifier
1>d:\c++projects\tutorialearning\tutorialearning\tutorialearning.cpp(15) : error C2065: 'endl' : undeclared identifier
1>d:\c++projects\tutorialearning\tutorialearning\tutorialearning.cpp(16) : error C2065: 'cin' : undeclared identifier
1>d:\c++projects\tutorialearning\tutorialearning\tutorialearning.cpp(16) : error C2065: 'x' : undeclared identifier
1>d:\c++projects\tutorialearning\tutorialearning\tutorialearning.cpp(17) : error C2065: 'cout' : undeclared identifier
1>d:\c++projects\tutorialearning\tutorialearning\tutorialearning.cpp(17) : error C2065: 'x' : undeclared identifier
1>d:\c++projects\tutorialearning\tutorialearning\tutorialearning.cpp(17) : error C2065: 'endl' : undeclared identifier
1>d:\c++projects\tutorialearning\tutorialearning\tutorialearning.cpp(17) : error C3861: 'doublenumber': identifier not found
1>Build log was saved at "file://d:\c++projects\tutorialearning\tutorialearning\Debug\BuildLog.htm"
1>tutorialearning - 9 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I really appreciate if you help me and such, thank you!!

3
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by gangsta1903
0
#include "stdafx.h"
#include <iostream>

using namespace std;


int doubleNumber(int x)
{
	return 2 * x;
}

int main()
{   
	cout << "Number to double: " << endl;
	cin >> x;
	cout << "Doubled number: " << doublenumber(x) << endl;
	return 0;
}

Edited by gangsta1903: n/a

0

of course it does not work because;
You are using a variable x without declaring it first.
You declare the functions doubleNumber but call doublenumber. They are different, C++ is case sensitive.

here it is fixed:

#include "stdafx.h"
#include <iostream>

using namespace std;


int doubleNumber(int x)
{
	return 2 * x;
}

int main()
{   
	int x;
	cout << "Number to double: " << endl;
	cin >> x;
	cout << "Doubled number: " << doubleNumber(x) << endl;
	return 0;
}

Edited by gangsta1903: n/a

Votes + Comments
He told me to fix easy things that I have fogotten. Thank you!
Stop doing homework for people. Let them do it with your help.
1

> #include <stdafx.h>
Delete this line,

then do
Project->Settings->Compiler (or pre-processor - depends on which VS you have).

Look for the option that configures "use precompiled headers".
Then turn it OFF.

Votes + Comments
Fixed my problem, fast and easy. Any other forums haven't even answered after days. Thank you!
0

Thank you Gangsta, I fixed that but I still get one of the errors, I think it's something that Salem talks about.. Salem I cannot find that option, im using

Visual Studio C++ 2008

And I really think that's how to fix this problem, please if you can clarify where that settning is, I have searched everywhere. Thank you

Here is the error, if anything has changed:

1>------ Build started: Project: tutorialearning, Configuration: Debug Win32 ------
1>Compiling...
1>tutorialearning.cpp
1>d:\c++projects\tutorialearning\tutorialearning\tutorialearning.cpp(4) : warning C4627: '#include <iostream>': skipped when looking for precompiled header use
1>        Add directive to 'stdafx.h' or rebuild precompiled header
1>d:\c++projects\tutorialearning\tutorialearning\tutorialearning.cpp(21) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
1>Build log was saved at "file://d:\c++projects\tutorialearning\tutorialearning\Debug\BuildLog.htm"
1>tutorialearning - 1 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

EDIT: I fixed it, searched google and found an answer! Thank you mate, I have learned lot's of things from you guys! Here is the fix for any googlers:

Project -> "projectname" Properties  ->Configuration properties -> C++ ->  Precompiled Headers -> Not Using Precompiled Headers

Edited by eddan: n/a

2

go to
project->properties->configuration properties->C/C++ -> precompiled headers

on the right panel, set Create/Use precompiled Header as "Not Using Precompiled Headers" from the options of drop-down box.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.