Hi people i'm a newbie here but i hope to be here a while.
I've just finished the tutorial book on C++ and i'm really getting a taste for it i think...Anyway, i thought for my first program i'de write a simple piece of code involving one function. The aim is to find out how many full days of the year i spend sleeping by finding out how many hours a night i sleep on average.
Here's my code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#include <iostream>
using namespace std;
#define yeardays 365
int sleepdaysum (int sleephours)
{
int sleepdays;
sleepdays=sleephours * yeardays / 24;
return (sleepdays);
}
int main ()
{
int theresult;
int gethours;
cout << "How many hours a night do you sleep: ";
cin >> gethours;
theresult = sleepdaysum (gethours) ;
cout << "You sleep "<< theresult << " days average a year";
return 0;
}
|
The big error i get is "Unable to open include file iostream" which snowballs other errors down the code. I have set the directories right so it's not that.
I know that instead i could write
#include <iostream.h>
which does work (opens) but then using namespace gives me the error of declaration or syntax or something..(i know that this is because i don't need "using namespace" with iostream.h)..Anyway, after writing it this way (iostream.h way, without namespace) my program goes all funny on me, showing on screen "The result8isThe result is8 How many hours a night do you sleep:"
I'de love it if someone could tell me why i cant open iostream (without the .h) and if my codes ok?
Thanks people...Oh! and i'm using Borland Turbo C++ Version 4.5 to compile (or trying to at least)
Thanks again...Benny26