- #1
lcam2
- 28
- 0
1.
write and test a c++ function named MakeMilesKmTable() to display a table of miles converted to kilometers. the argument to the function should be the starting and stopping values of miles and the increment. the output should be a table of miles and their equivalent kilometer values. use the relationship that 1 mile = 1.61 km.
Then modify the function so that the two columns are printed. For example, if the starting value is 1 mile, the ending value is 20 miles, and the increment is 1.
Miles Kilometers Miles Kilometeres
1 1.61 11 17.70
2 3.22 12 19.31
3 . . .
. . . .
. . . .
10 16.09 20 32.18
My problem is that i can run the first part, but i don't know how to display
the other part of the table. If anyone can give me some help i will really apreciaate it.
Thanks in advance
Book Link
http://books.google.com/books?id=5-...ble of miles converted to kilometers.&f=false
1 mile = 1.61 Kilometers
Hint: Find, split =(start +stop)/2. let a loop execute from miles = start to split, and calcualte and print across one line the values of miles and kilometers for both miles and (miles-start+split+1)
#include <iostream>
#include <iomanip>
using namespace std;
double MakeMilesKmTable ( double, double, int); //Fuction Prototype
int main ()
{
double start = 1; //Variabledeclaration
double stop = 20;
int increment =1;
cout << "This Program converts from Miles to Kilometers." << endl;
cout << endl;
cout << "Miles \t Kilometers" << setw(10) << "Miles \t Kilometers" << endl;
cout << "---------------------------" << endl;
MakeMilesKmTable (start, stop, increment); //Calling the function
return 0;
}
//Function MakeMilesKmTable
double MakeMilesKmTable ( double start, double stop, int increment)
{
double MileToKilo, split;
split = ( start + stop )/ 2.0;
for (double i=start; i <= split; i++)
{
MileToKilo = i * 1.61;
cout << i << setw(15) << MileToKilo << "\t" << (i - start + split +1 ) << endl;
}
return MileToKilo;
}
write and test a c++ function named MakeMilesKmTable() to display a table of miles converted to kilometers. the argument to the function should be the starting and stopping values of miles and the increment. the output should be a table of miles and their equivalent kilometer values. use the relationship that 1 mile = 1.61 km.
Then modify the function so that the two columns are printed. For example, if the starting value is 1 mile, the ending value is 20 miles, and the increment is 1.
Miles Kilometers Miles Kilometeres
1 1.61 11 17.70
2 3.22 12 19.31
3 . . .
. . . .
. . . .
10 16.09 20 32.18
My problem is that i can run the first part, but i don't know how to display
the other part of the table. If anyone can give me some help i will really apreciaate it.
Thanks in advance
Book Link
http://books.google.com/books?id=5-...ble of miles converted to kilometers.&f=false
Homework Equations
1 mile = 1.61 Kilometers
Hint: Find, split =(start +stop)/2. let a loop execute from miles = start to split, and calcualte and print across one line the values of miles and kilometers for both miles and (miles-start+split+1)
The Attempt at a Solution
#include <iostream>
#include <iomanip>
using namespace std;
double MakeMilesKmTable ( double, double, int); //Fuction Prototype
int main ()
{
double start = 1; //Variabledeclaration
double stop = 20;
int increment =1;
cout << "This Program converts from Miles to Kilometers." << endl;
cout << endl;
cout << "Miles \t Kilometers" << setw(10) << "Miles \t Kilometers" << endl;
cout << "---------------------------" << endl;
MakeMilesKmTable (start, stop, increment); //Calling the function
return 0;
}
//Function MakeMilesKmTable
double MakeMilesKmTable ( double start, double stop, int increment)
{
double MileToKilo, split;
split = ( start + stop )/ 2.0;
for (double i=start; i <= split; i++)
{
MileToKilo = i * 1.61;
cout << i << setw(15) << MileToKilo << "\t" << (i - start + split +1 ) << endl;
}
return MileToKilo;
}