[Dev-C++] Peter You Problem I Solved the Problem.
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Purohit P. J. <pra...@si...> - 2001-03-06 15:16:28
|
In your Program You tried (km_travelled%1000) I guess you wanted to find =
the remainder when km_travelled divided by 1000 The Modulus Operator % =
works only with integers. If you want to find remainder use integer =
parsing. The Corrected Program Is Included Below....
#include <iostream.h>
void main()
{
float ini_reading;
float fin_reading;
float km_travelled;
float trav_cost;
float wear_cost;
// Title.
cout << "Calculate the hire car cost. \n\n";
// Ask for initial odometer reading.
cout << "Please Enter the initial odometer reading :";
cin >> ini_reading;
// Ask for finial reading.
cout << endl;
cout << "Please Enter the finial odometer reading :";
cin >> fin_reading;
// Calculate costs.
km_travelled =3D (fin_reading - ini_reading);
trav_cost =3D (km_travelled * 0.3);
wear_cost =3D ((km_travelled / 1000) - (((int)km_travelled % 1000) =
/ 100) *
200);
// Display total hire car cost.
cout << "The total hire car cost is $" << (wear_cost + trav_cost);
cout << endl << endl;
// Finish program.
cin.ignore(1);
cin.get();
}
Prahlad J. Purohit...
PH: +91-22-8143953
|