Question:
I need help with 2008 Visual studio c++?
hr3cu8tu99
2008-09-04 19:14:09 UTC
I'm trying to do a win32 console application averaging of numbers
I've included the code exactly as I typed it
and then clicking on build and compile

I also listed the error message after I tried to compile

Is there a step I'm missing?


#include "stdafx.h"
using namespace std;


int main(void)
{
double# dnumber1 = 0.0;
double# dnumber2 = 0.0;
double# dnumber3 = 0.0;
double# daverage = 0.0;

cout << "please enter 3 numbers; " << endl;
cin >> dnumber1;
cin >> dnumber2;
cin >> dnumber3;

daverage = (dnumber1 + dnumber2 + dnumber3) / 3;
cout << "the average of the numbers are: " << daverage << endl << endl;
system ("pause")
return 0;




This is the error message


1>------ Build started: Project: PROJECT, Configuration: Debug Win32 ------
1>Compiling...
1>PROJECT.cpp
1>c:\users\kevin\documents\visual studio 2008\projects\project\project\project.cpp(1) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
1>c:\users\kevin\documents\visual studio 2008\projects\project\project\project.cpp(1) : warning C4627: '#include ': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header
1>c:\users\kevin\documents\visual studio 2008\projects\project\project\project.cpp(23) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
1>PROJECT - 1 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Five answers:
Mani S
2008-09-04 19:29:51 UTC
Try adding #include to "stdafx.h" Hope this helps. If it does, please mark my answer as the best one. Happy programming!!:-)
Damasta AM inductee
2008-09-04 19:27:15 UTC
include "stdafx.h"

#include

//Professional code doesn't use

using namespace std;





int main(void)

{

double dnumber1 = 0.0;

double dnumber2 = 0.0;

double dnumber3 = 0.0;

double daverage = 0.0;



cout << "please enter 3 numbers: " << endl;

cin >> dnumber1;

cin >> dnumber2;

cin >> dnumber3;



daverage = (dnumber1 + dnumber2 + dnumber3) / 3;

cout << "the average of the numbers are: " << daverage <<"\n\n";

cin.get();/*It was recommended to do this because in cross-platform code, system() commands won't work like they would in Windows*/

return 0;
?
2016-11-04 12:17:31 UTC
Preprocessor Directive Expected
Chie
2008-09-04 19:24:21 UTC
All is in the first line:



#include "stdafx.h"



Is "stdafx.h" really supposed to be there? Or should it be:

#include

#include "stdafx.h"
2008-09-04 19:24:12 UTC
It's barfing up your #include line. Fix it.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...