//I have this running but when the user inputs a different character than the program just out puts the error //message and that its. I want it to go back and ask the user if they would like to run the program again. Any //ideas? Thank you!

int main ()
{
    double a = 0;
    double b = 0;
    double c = 0;
    double r1 = 0;
    double r2 = 0;
    char answer;
    
    do 
    {
        try 
        {
            //Greeting
            pa7functions::greeting();
            //Gets the values of a,b, and c
            pa7functions::get_coefficients(a, b, c);
            //Figures if a, b, and c are roots
            pa7functions::computeRoots(r1, r2, a, b, c);
            //Displays the roots
            pa7functions::display_roots(r1,r2);
        } 
        catch (matherror& m) 
        {
            m.display();
        }
        std::cout << "Would you like to run the program again?(y-yes, n-no)\n";
        std::cout << "Answer: ";
        std::cin >> answer;
        if (answer != 'n' || answer != 'N' || answer != 'y' || answer != 'Y') 
        {
            std::cout << "\nPlease enter a character: Y for YES or N for NO.\n";
            std::cin.clear();
            std::cin.ignore(100);
            return EXIT_FAILURE;
        }
        else
        {
            return EXIT_SUCCESS;
        }
    }
    while (answer != 'n');
    return EXIT_SUCCESS;}

Edited 5 Years Ago by WaltP: n/a

//I have this running but when the user inputs a different character than the program just out puts the error //message and that its. I want it to go back and ask the user if they would like to run the program again. Any //ideas?

Yep.
1) Use CODE Tags when posting.
2) Use a loop when you get a bad character.

your line:

if (answer != 'n' || answer != 'N' || answer != 'y' || answer != 'Y')

Will never return false. The "||" operator is an OR, not an AND. The variable answer can't be all four of the values you test, so at least three of the comparisons will return true, which means the overall boolean statement will return true.

You also don't want those returns in your do loop. That will cause your program to exit.

Finally, I don't think you want the ignore call; I don't see what that's doing for you, and it will give your program odd results.

This article has been dead for over six months. Start a new discussion instead.