Hi all,
The program can't clear the memory space after user entered a invalid choice. It works fine for numeric 0 - 9 but if i enter an alphabet, the text 'invalid choice' will be displayed twice (IE: after showing the error message, it'll show again in "Enter Choice: ", hence preventing user from entering a choice).
I can't find where the error lies... hope someone can help me out.Code:#include <iostream.h>
#include <stdlib.h>
// To pause the screen for user to read.
void pause(void)
{
getchar();
}
void main(void)
{
int choice;
do
{
system("cls");
cout << "=========================" << endl;
cout << "1.) Contacts" << endl;
cout << "2.) Messaging" << endl;
cout << "3.) Make Call" << endl;
cout << "4.) Call Log" << endl;
cout << "5.) Accessories" << endl;
cout << "6.) Tools" << endl;
cout << "7.) Off Mobile" << endl;
cout << "=========================" << endl;
cout << "Please select a menu: ";
cin >> choice;
switch (choice)
{
case 1 : contacts();
break;
case 2 : cout << "go to messaging" << endl;
pause();
break;
case 3 : cout << "go to make call" << endl;
pause();
break;
case 4 : cout << "go to call log" << endl;
pause();
break;
case 5 : accessories();
break;
case 6 : tools();
break;
case 7 : // prints quit msg.
break;
default:
cout << "Invalid Choice!" << endl;
pause();
break;
}
} while (choice!=7);
cout << "Program terminating..." << endl;
}
PS: There are other functions in this program which I didn't paste it out because it's not revelant to the error that's occuring.
Thanks :)