| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help With Small Program
Okay Im just messing around and I decided on calculating
miles per gallon in a car. Ive got the program pretty much set up, but when I have it ask to input a value, it skips through most of the program instead of allowing a user to insert a number. Im a new programmer so bear with my coding........ Code:
// Calculation of Miles Per Gallon
// Version 1.0
// Josh Lardino
#include <iostream>
using namespace std;
int pricePerGallon;
int gallons;
int milesPerGallon;
int tripMiles;
int main()
{
cout << "|--------------------------------------------|" << endl;
cout << "| MPG (Miles Per Gallon) Calculator |" << endl;
cout << "| Created By: Josh Lardino |" << endl;
cout << "| Version 1.0 |" << endl;
cout << "| Last Updated: November 09, 2004 |" << endl;
cout << "|--------------------------------------------|" << endl;
cout << endl;
cout << endl;
cout << "This program is to calculate the fule mileage of your \n"
"vehicle." << endl;
cout << "What Youll Need: 1) Gas Reciept. 2) Last displayed \n"
"trip mileage of your car." << endl;
cout << endl;
cout << "Follow the next directions to calculate your vehicles \n"
"mileage. Thanks for using this program." << endl;
cout << endl;
cout << endl;
cout << "Take your gas reciept and enter the price per gallon." << endl;
cout << "Enter Price Per Gallon: $";
cin >> pricePerGallon;
cout << endl;
cout << "Now enter in the amount of gas you put into your \nvehicle. (In Gallons)" << endl;
cout << "Enter Gallons of Gas: ";
cin >> gallons;
cout << endl;
cout << "Now enter in the last displayed trip mileage of your \nvehicle. (In miles)" << endl;
cout << "Enter Trip Miles: ";
cin >> tripMiles;
cout << endl;
milesPerGallon = tripMiles / gallons;
cout << "Your car gets " << milesPerGallon << " miles per gallon. \n"
"Thank you again for using this program." << endl;
cout << endl;
cout << endl;
return 0;
}
|
|
#2
|
|||
|
|||
|
Works on my compiler (VC++ 6.0)
|
|
#3
|
|||
|
|||
|
Wonder why its not working with mine. Using Visual C++
but when I run the program (f5), I place one value, then after I press enter, it skips the other two values and just ends the program. |
|
#4
|
|||
|
|||
|
I don't know if this will help but you might try declaring your variables within the int main() function since you don't
really need to declare global variables. Other than that your program seems fine and would run. In VC++ 6.0 you might try closing the workspace and opening a new workspace. Hope any of that helps. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Help With Small Program |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|