-1

hi,
in this code:

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

int main()
{
    using namespace std;
    cout << "Enter a value: ";
    double dX;
    cin >> dX;
 
    cout << "Enter a second value: ";
    double dY;
    cin >> dY;
 
    cout << "Enter one of the following: +, -, *, or /";
    char chChoice;
    cin >> chChoice;
 
    if (chChoice == '+')
        cout << dX << " + " << dY << " is " << dX + dY << endl;
    if (chChoice == '-')
        cout << dX << " - " << dY << " is " << dX - dY << endl;
    if (chChoice == '*')
        cout << dX << " * " << dY << " is " << dX * dY << endl;
    if (chChoice == '/')
        cout << dX << " / " << dY << " is " << dX / dY << endl;
 
    return 0;
}

this code works only, when i put #include "stdafx.h" before #include <iostream> what is the reason

regards
iammfa

Edited by Nick Evan: Added code-tags

Votes + Comments
>10 posts, still NO ***** CODE TAGS
4
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by iammfa
0

Don't use <pre> and </pre>!, use the code tags: [ code=cplusplus ]...[ /code ], without spaces!

Thanks!

Edited by Nathan Campos: put in bold

0

I'm using c++ 2008 express, i removed stdafx.h, but the error return:

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

Having removed the stdafx.h abomination, you ALSO need to do

project->settings->compiler->pre-processor->precompiled headers and turn it OFF.

OK, the last couple of steps may vary, but you get the idea of where to start looking.

This topic has been dead for over six months. 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.