-
April 27th, 2009, 09:45 AM
#1
Homework Function Help.
Below i Have 3 different functions I wrote for a homework assignment. I'm not sure what is wrong with them. Any help would be GREATLY Appreciated.
void airfare(double &airfareCost, double &airfareAllowd)
{
Cout<< "Enter cost of airefare"<<endl;
cin>> airfareCost<<endl;
airfareAllowd=airfareCost;
}
void milage(int miles, double &milageCost, double&milageAllowd)
{
cout<< "Enter cost of airefare"<<endl;
cin>> milageCost<<endl;
cout<<"Enter number of miles"<<endl;
cin<<miles<<endl;
milageAllowed= miles* 0.38 ;
}
Void taxi(int taxiDays, double &taxiCost, double&taxiAllowd)
{
cout<< "Enter number of days travelled"<< endl;
cin>>taxiDays<<endl;
cout<< "Enter Total cost of Taxi"<<endl;
cin>>taxiCost<<endl;
taxiAllowed=taxiDays * 10 ;
}
Last edited by Poeticsoul44; April 27th, 2009 at 09:47 AM.
-
April 27th, 2009, 10:28 AM
#2
Re: Homework Function Help.
C++ is case sensitive.
Pay attention to the direction when using << and >>.
Use whitespace for improved readability.
-
April 27th, 2009, 10:30 AM
#3
Re: Homework Function Help.
So I messed up on << and >>? Was that the only thing?
-
April 27th, 2009, 10:35 AM
#4
Re: Homework Function Help.
Originally Posted by Poeticsoul44
So I messed up on << and >>? Was that the only thing?
I don't do a lot of console programming, but I'm not sure sending endl to cin makes any sense.
I also mentioned that C++ is case sensitive.
-
April 27th, 2009, 10:38 AM
#5
Re: Homework Function Help.
Yea. I caught the error..But theres something else wrong with it because they wont compile for some reason.
-
April 27th, 2009, 10:45 AM
#6
Re: Homework Function Help.
Originally Posted by Poeticsoul44
Yea. I caught the error..But theres something else wrong with it because they wont compile for some reason.
There are lots of errors. I already pointed out the category. What does the compiler say?
Last edited by GCDEF; April 27th, 2009 at 10:49 AM.
-
April 27th, 2009, 11:00 AM
#7
Re: Homework Function Help.
the first gives the following errors:
air.cpp: In function âvoid airfare(double&, double&)â:
air.cpp:3: error: âcoutâ was not declared in this scope
air.cpp:3: error: âendlâ was not declared in this scope
air.cpp:4: error: âcinâ was not declared in this scope
air.cpp:5: error: âairefareAllowedâ was not declared in this scope
air.cpp:5: error: âairefareCostâ was not declared in this scope
The second funtion i get these errors:
miles.cpp: In function âvoid milage(int, double&, double&)â:
miles.cpp:3: error: âcoutâ was not declared in this scope
miles.cpp:3: error: âendlâ was not declared in this scope
miles.cpp:4: error: âcinâ was not declared in this scope
And the third gives me these errors:
taxi.cpp: In function âvoid taxi(int, double&, double&)â:
taxi.cpp:3: error: âcoutâ was not declared in this scope
taxi.cpp:3: error: âendlâ was not declared in this scope
taxi.cpp:4: error: âcinâ was not declared in this scope
[wm136158@adanew ~]$
-
April 27th, 2009, 11:12 AM
#8
Re: Homework Function Help.
Did you include iostream?
-
April 27th, 2009, 11:25 AM
#9
Re: Homework Function Help.
I just did and i get these errors for the first:
air.cpp: In function âvoid airfare(double&, double&)â:
air.cpp:4: error: âcoutâ was not declared in this scope
air.cpp:4: error: âendlâ was not declared in this scope
air.cpp:5: error: âcinâ was not declared in this scope
air.cpp:6: error: âairefareAllowedâ was not declared in this scope
air.cpp:6: error: âairefareCostâ was not declared in this scope
For the second i get:
miles.cpp: In function âvoid milage(int, double&, double&)â:
miles.cpp:4: error: âcoutâ was not declared in this scope
miles.cpp:4: error: âendlâ was not declared in this scope
miles.cpp:5: error: âcinâ was not declared in this scope
and the third i get:
taxi.cpp: In function âvoid taxi(int, double&, double&)â:
taxi.cpp:4: error: âcoutâ was not declared in this scope
taxi.cpp:4: error: âendlâ was not declared in this scope
taxi.cpp:5: error: âcinâ was not declared in this scope
-
April 27th, 2009, 11:26 AM
#10
Re: Homework Function Help.
Post your entire code as it is now.
-
April 27th, 2009, 11:29 AM
#11
Re: Homework Function Help.
First function code:
#include <iostream>
void airfare(double &airfareCost, double & airfareAllowed)
{
cout<< "Enter cost of airfare"<<endl;
cin>>airfareCost;
airefareAllowed=airefareCost;
}
2nd:
#include <iostream>
void milage(int miles,double &milageCost, double&milageAllowed)
{
cout<<"Enter cost of milage"<<endl;
cin>>milageCost;
cout<<"enter number of mile"<<endl;
cin>>miles;
milageAllowed= miles * 0.38;
}
3rd:
#include <iostream>
void taxi(int taxiDays, double &taxiCost, double&taxiAllowed)
{
cout<< "Enter number of days travelled"<<endl;
cin>>taxiDays;
cout<<"enter total cost of taxi"<<endl;
cin>>taxiCost;
taxiAllowed=taxiDays *10;
}
-
April 27th, 2009, 11:29 AM
#12
Re: Homework Function Help.
You forgot to put
Code:
using namespace std;
at the top.
And there's no need to #include a file more than once in a given cpp.
-
April 27th, 2009, 11:38 AM
#13
Re: Homework Function Help.
I just included "using namespace std;" and get these errors:
1st:
air.cpp: In function âvoid airfare(double&, double&)â:
air.cpp:7: error: âairefareAllowedâ was not declared in this scope
air.cpp:7: error: âairefareCostâ was not declared in this scope
2nd:
miles.cpp: In function âvoid milage(int, double&, double&)â:
miles.cpp:4: error: âcoutâ was not declared in this scope
miles.cpp:4: error: âendlâ was not declared in this scope
miles.cpp:5: error: âcinâ was not declared in this scope
3rd:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
-
April 27th, 2009, 11:42 AM
#14
Re: Homework Function Help.
You're going to have to give us more to work with if you want help sorting this out.....
-
April 27th, 2009, 11:53 AM
#15
Re: Homework Function Help.
What all do you want to know?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|