| | |
figure this out
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2003
Posts: 58
Reputation:
Solved Threads: 0
well this is what my program does:
//asks for input for number of gallons
enter the gallons of gas used (-1 to end):
//asks for input for number of miles
enter miles driven:
//then shows the miles / gallon for this tank
the miles / gallon for this tank was ...
it loops this untill the user presses -1
then i want it to find out the avg of all the miles/gallons.
problem is that avg is over written every time the loop starts
here is the code for the program.
#include <iostream.h>
#include <conio.h>
float gal;
float avg;
void gas();
//void totalavg();
void main()
{
while(gal>=0)
gas();
getch();
}
void gas()
{
float miles;
cout <<"enter the gallons of gas used (-1 to end): ";
cin >> gal;
if(gal!=-1)
{
cout <<"enter miles driven: ";
cin >> miles;
avg=miles/gal;
cout <<"the miles / gallon for this tank was "<<avg<<endl;
cout<<"\n";
}
}
i think i need avg to be a array.
anyhelp or hints to this problem would be greatly apprecaited.
//asks for input for number of gallons
enter the gallons of gas used (-1 to end):
//asks for input for number of miles
enter miles driven:
//then shows the miles / gallon for this tank
the miles / gallon for this tank was ...
it loops this untill the user presses -1
then i want it to find out the avg of all the miles/gallons.
problem is that avg is over written every time the loop starts
here is the code for the program.
#include <iostream.h>
#include <conio.h>
float gal;
float avg;
void gas();
//void totalavg();
void main()
{
while(gal>=0)
gas();
getch();
}
void gas()
{
float miles;
cout <<"enter the gallons of gas used (-1 to end): ";
cin >> gal;
if(gal!=-1)
{
cout <<"enter miles driven: ";
cin >> miles;
avg=miles/gal;
cout <<"the miles / gallon for this tank was "<<avg<<endl;
cout<<"\n";
}
}
i think i need avg to be a array.
anyhelp or hints to this problem would be greatly apprecaited.
![]() |
Similar Threads
- New programming language: Who can figure it out? (Computer Science)
- Matlab - figure caption (Computer Science)
- Figure this one out (CD ROM) (Storage)
- Floating Menus: I have a problem, can you help me figure it out? (HTML and CSS)
- Homework Help for C++ Beginner -- I've tried and tried, and can't figure it out!! (C++)
- help with significant figure function (C)
- Cannot figure out why I'm getting these Errors (Java)
Other Threads in the C++ Forum
- Previous Thread: help about programming
- Next Thread: stuck with definition
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets





