int Menu::showMenu() {
	unsigned int option;
	bool valid = false;
	cout << title << endl;

	for(unsigned int i = 0; i<items.size(); i++) {
		cout << i + 1 << " - " << items[i] << endl;
	}

	while(!valid) {
		option = promptInt("Choose an option: ");
		valid = false;
		for (unsigned int i = 0; i<items.size(); i++) {
			if(i+1 == option) {
				valid = true;
			}
		}

		if(!valid) {
			cout << endl << "This input is not valid. Please try and follow the indicated instructions." << endl << endl;
		}
	}
	cout << endl;
	return option;
}
Exemplo n.º 2
0
int promptSize(int* size) {
    int success = promptInt(size);
    if (*size < 0) {
        success = 0;
    }

    return success;
}
Exemplo n.º 3
0
int main(void) {
    int size;
    int validInput = 0;

    printf("BoundedQueue:\n\n");

    while (!validInput) {
        printf("Enter desired queue size: ");

        validInput = promptSize(&size);
        if (!validInput) {
            printf("invalid size\n");
        }
    }

    BoundedQueue bq(size);

    char cmd[3]; /* to hold "x\n\0" where x = command letter */
    while (cmd[0] != 'q') {
        printf("Enter command - (e)nqueue, (d)equeue, or (q)uit: ");
        validInput = promptString(cmd, 3);
        if (!validInput) {
            printf("invalid\n");
            continue;
        }
        int element;
        if (cmd[0] == 'e') {
            printf("Enter integer to enqueue: ");
            promptInt(&element);
            bq.enqueue(element);
            if (size <= 25) {
                printQueue(bq);
                printf("\n");
            }
        }
        else if (cmd[0] == 'd') {
            printf("Dequeued integer: %d\n", bq.dequeue());
            if (size <= 25) {
                printQueue(bq);
                printf("\n");
            }
        }
    }


    return 0;
}