Thread: C++ Miles Program

1. C++ Miles Program

I need help with this program. I'm compiling in Visual C++

Code:
```#include "stdafx.h"

#include <iostream>

float getdata();
using namespace std;

int main()
{
float milesperhour;
milesperhour=getdata();
cout<<"\nMiles per Hour="<<milesperhour;
cin.ignore();
cin.get();
return 0;
}

float getdata()
{
float miles, hours;
cout<<"\nEnter Miles:";
cin>>miles;
cout<<"\nEnter hours:";
cin>>hours;
miles/hours);

return 0;

}```
fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory
Error =

2. something is wrong with your installation of VC++. (the compiler cannot find the standard library)

3. I changed the codes: <iostream> is normally stored in the C:\Program Files\Microsoft Visual Studio 8\VC\include folder. First check if it is still there. Then choose Tools + Options, Projects and Solutions, VC++ Directories, choose "Include files" in the "Show Directories for" combobox and double-check that \$(VCInstallDir)include is on top of the list.

But I'm still getting the error
Code:
```#include <iostream.h>

#include <iomanip.h>

float getdata();
using namespace std;```

4. What error? Cannot open include file: 'iostream.h'? Or the new file 'iomanip.h'?

Also your getdata() function is always returning 0, not what you want. And there is a ')' after miles/hours that doesn't belong. and you aren't assigning this division to a variable.

5. Error = fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory

Also since I'm using Visual C++ should I add

#include "stdafx.h"

6. 'iostream.h' is outdated header it should not be included in your project at all
Also since I'm using Visual C++ should I add

#include "stdafx.h"
only if you are using precompiled headers - better disable them and you could get rid of stdafx.h

7. Thank you all. It worked! :-)

Popular pages Recent additions