Thread: Program error

  1. #1
    Registered User
    Join Date
    May 2002

    Question Program error

    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:

    // Miles to Kilometers conversion
    #include <iostream>
    using namespace std;
    float mtokm(int);
    int miles = 0;
    int main()
    	char keypress;
    		cout << "\n\nEnter the amount of miles you want converted to kilometers: ";
    		cin >> 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.

  2. #2
    Registered User
    Join Date
    May 2002

    thank you

    Thanks.. i had misstated what I meant, I meant to say when I try to exit with a different key the program still continues. But you knew what I meant. That fixed the problem, thanks again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  2. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 03:35 PM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
Website Security Test