John Quickdraw
John Quickdraw

Reputation: 1

Changing the "Press any key to Continue..." in C++ using Visual Basics

For every program we've wrote so far in class it ends with the default "Press any key to continue..." How do I change this? I've tried using

cout<< "Press any key to end the program"; system("pause>"nul)

But it still displays "press any key to continue" one I enter a key. Any ideas?

Here's what I have thus far (feel free to point out how I can improve in other areas as well!) `

#include <iostream>
using namespace std;
#include <string>
using namespace std;
int main()
{
    //Declaring my varibles
    double persons = 0;
    double tier1 = 125;
    double tier2 = 100;
    double tier3 = 75;
    double cost = 0;
    string hyphens = "";
    system("cls");
    cout << "-------------------------------------------------- " << endl;
    cout << "Computer Programming Seminar" << endl;
    cout << "-------------------------------------------------- " << endl<<endl;
    cout << "Please enter the number of registrants: ";
    cin >> persons;
    cout << hyphens << endl;
    if (0 < persons && persons < 6)
        cost = persons * tier1;

    else if (5 < persons && persons < 21)
        cost = persons *tier2;

    else if (persons >= 21)
        cost = persons*tier3;
    else
    {
        cost = 0;
        cout << "Invalid Entry" <<endl << endl;
    }

    cout << "Total Amount Owed for the Seminar: $" << cost << endl;
    cout << "-------------------------------------------------- " << endl;
    cout << endl << endl << "Press any key to end the Seminar Program";
    system("pause>nul");
    return 0;

Upvotes: 0

Views: 3802

Answers (4)

Ozaku
Ozaku

Reputation: 1

I just changed the console foreground and background color to black after using Console.WriteLine to display a custom ending message

It looks slightly sloppy to have the cursor dangling out in midair, but it's also super easy and won't really cause issues.

Upvotes: 0

Remy Lebeau
Remy Lebeau

Reputation: 597166

The message you want to avoid does not come from your program at all. It comes from the pause command. So, if you want to avoid the message, don't call system("pause") anymore. Do your own I/O in your own code.

Upvotes: 0

Thomas Matthews
Thomas Matthews

Reputation: 57728

My pattern is:

std::cout << "Paused. Press Enter to continue.";
std::cin.ignore(100000, '\n');

You can change the prompt to whatever you want.

Upvotes: 4

Ali Sepehri-Amin
Ali Sepehri-Amin

Reputation: 493

Press any key to continue... it's default value and it's never changes. You can try #include <conio.h> and Instead of system("pause"); Use:

_getch();

Upvotes: 1

Related Questions