Hi, i'm having trouble with the following very simple program, which converts miles to kilometers. When I try to exit out of the program entering C or c, the program still continues. Any help with this would be greatly appreciated. Here's the code:
Code:
// Miles to Kilometers conversion
#include <iostream>
using namespace std;
float mtokm(int);
int miles = 0;
int main()
{
char keypress;
do
{
cout << "\n\nEnter the amount of miles you want converted to kilometers: ";
cin >> miles;
mtokm(miles);
(miles == 1 ? cout << "\n\n1 mile" : cout << "\n\n" << miles << " miles") << " is equal to " << mtokm(miles) << " kilometers.\n\n";
cout << "Press C to do another conversion, or any other key to quit: ";
cin >> keypress;
}
while (keypress == 'c' || 'C');
return 0;
}
float mtokm(int)
{
float kilometers;
kilometers = ::miles * 1.61;
return kilometers;
}
Thanks in advance.