C++ Miles Program

This is a discussion on C++ Miles Program within the C++ Programming forums, part of the General Programming Boards category; I need help with this program. I'm compiling in Visual C++ Code: #include "stdafx.h" #include <iostream> float getdata(); using namespace ...

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    24

    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. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    something is wrong with your installation of VC++. (the compiler cannot find the standard library)

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    24
    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. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    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. #5
    Registered User
    Join Date
    May 2008
    Posts
    24
    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. #6
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,458
    '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
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  7. #7
    Registered User
    Join Date
    May 2008
    Posts
    24
    Thank you all. It worked! :-)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 10:17 PM
  3. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  4. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21