P
Philipp.Weissenbacher
Hi all!
I wrote the following as a test case for a menu based programme:
#include <iostream>
#include <cstring>
using namespace std;
#define cls system("cls")
const int SIZE = 10;
int numbers[SIZE];
void list() {
cls;
cout << "List" << endl << endl;
for(int i=0; i<SIZE; i++) {
cout << i << endl;
}
getchar(); // Doesn't work!
cls;
mainMenu();
}
void add() {};
void remove() {};
int mainMenu() {
char c;
do {
cout << "Main menu" << endl << endl;
cout << "(L)ist" << endl
<< "(A)dd" << endl
<< "(R)emove" << endl << endl
<< "(Q)uit" << endl << endl
<< "Selection: ";
cin >> c;
switch(c) {
case 'l': ; // Fallthrough to uppercase L
case 'L': list(); break;
case 'a': add(); break;
case 'r': remove(); break;
case 'q': break;
}
} while(c!='q');
return 0;
}
int main() {
// Init numbers
memset(numbers, 0, sizeof(int)*SIZE-1);
mainMenu();
return 0;
}
Why isn't the programme pausing and waiting for a RETURN key press
after listing the contents of numbers in the function list()?
Many thanks in advance,
Philipp
I wrote the following as a test case for a menu based programme:
#include <iostream>
#include <cstring>
using namespace std;
#define cls system("cls")
const int SIZE = 10;
int numbers[SIZE];
void list() {
cls;
cout << "List" << endl << endl;
for(int i=0; i<SIZE; i++) {
cout << i << endl;
}
getchar(); // Doesn't work!
cls;
mainMenu();
}
void add() {};
void remove() {};
int mainMenu() {
char c;
do {
cout << "Main menu" << endl << endl;
cout << "(L)ist" << endl
<< "(A)dd" << endl
<< "(R)emove" << endl << endl
<< "(Q)uit" << endl << endl
<< "Selection: ";
cin >> c;
switch(c) {
case 'l': ; // Fallthrough to uppercase L
case 'L': list(); break;
case 'a': add(); break;
case 'r': remove(); break;
case 'q': break;
}
} while(c!='q');
return 0;
}
int main() {
// Init numbers
memset(numbers, 0, sizeof(int)*SIZE-1);
mainMenu();
return 0;
}
Why isn't the programme pausing and waiting for a RETURN key press
after listing the contents of numbers in the function list()?
Many thanks in advance,
Philipp