inheritance

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2003
Posts: 58
Reputation: fakespike is an unknown quantity at this point 
Solved Threads: 0
fakespike fakespike is offline Offline
Junior Poster in Training

inheritance

 
0
  #1
Sep 15th, 2003
#include <iostream.h>
#include <conio.h>


void gas();
void main()
{
float gal;
while(gal<=0)
gas();

cout<<"thanks for your help";
getch();
}

void gas()
{
float gal;
float total;
float miles;
float avg;
cout <<"enter the gallons of gas used (-1 to end): ";
cin >> gal;
cout <<"enter miles driven: ";
cin >> miles;
avg=miles/gal;
cout <<"the miles / gallon for this tank was "<<avg<<endl;
cout<<"\n";
}
------------------------------------------------------------------------------
i'm tring to get float gal value to be shared between gas and main.
so that if -1 is enter for gal the while loop will exit.
help would be aprecaited.
Reply With Quote Quick reply to this message  
Join Date: Apr 2003
Posts: 46
Reputation: Dante Shamest is an unknown quantity at this point 
Solved Threads: 0
Dante Shamest's Avatar
Dante Shamest Dante Shamest is offline Offline
Light Poster
 
0
  #2
Sep 15th, 2003
You can either make gal a global variable, or pass rewrite gas() so that it receives a pointer to a integer. Then pass gal to gas().
Reply With Quote Quick reply to this message  
Join Date: Jul 2003
Posts: 58
Reputation: fakespike is an unknown quantity at this point 
Solved Threads: 0
fakespike fakespike is offline Offline
Junior Poster in Training

Re: inheritance

 
0
  #3
Sep 16th, 2003
i feel stupid now that the sulotion was so simple thanks for ur help that answered my question
Reply With Quote Quick reply to this message  
Join Date: Jul 2003
Posts: 58
Reputation: fakespike is an unknown quantity at this point 
Solved Threads: 0
fakespike fakespike is offline Offline
Junior Poster in Training

Re: inheritance

 
0
  #4
Sep 16th, 2003
i have faced some problems.
1)when -1 is pressed it doesnt exit immediately it finishes the function gas() first.
2)i have to then find the average of all the averages entered. but avg varible over writes its result. so correct me if i'm wrong but wont i have to create a array for avg.

then i have to present the average of avg for the passed serveral cars when -1 is pressed.

i know its a bit confusing so help would be greatly appreciated. sorry for my ignorance i'm still new and learning.
Reply With Quote Quick reply to this message  
Join Date: Oct 2003
Posts: 1
Reputation: yogesh is an unknown quantity at this point 
Solved Threads: 0
yogesh yogesh is offline Offline
Newbie Poster

Re: inheritance

 
0
  #5
Oct 9th, 2003
declare variable gal as global variable ( out of both the function above main() ) , remove local declaration of gal from both the function. you will be able to share same gal betn main and gas. I am showing you code snap

float gal = 0.0f;

main()
{
while( gal >= 0.0f)
{
gas()
}

}

gas()
{
// dont declare gal again in this function
....
cin<<gal; // same global gal
}
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC