Design a C++ program by considering the following conditions;
1. User must keyed-in “start” to start the program and “stop” to
end the program.
.
2. If the user keyed-in “choice1”, print out PATTERN A.
3. If the user keyed-in “choice2”, print out PATTERN B.
Use if else statement, while loop, nested for loop and switch case statement
in your program.

A B 1 2
C D 3 4
E 5
1 2 A B
3 4 C B

SOL(INCOMPLETE):

#include <iostream>
#include <string>
using namespace std;
int main()
{
    char a = 'A';
    int choice1, choice2, choice, col, row;
    cout << "Enter choise1 for pattern A, or choise2 for pattern B\n";


    for (row = 1; row <4; row++){
        for (col = 1; col <6; col++){
            if (row == col || col == (5 + 1) - row){
                cout << a;
                a++;
            }
            else
                cout << " ";
        }
        cout << endl;
    }
    int x;
    x = 1;
    for (row = 1; row < 2; row++){
        for (col = 1; col < 6; col++){
            if (col == row + 1 || col == row + 3){
                cout << x;
                x++;
            }

            else
                cout << " ";
        }

        cout << endl;
    }

    for (row = 1; row < 2; row++){
        for (col = 1; col < 6; col++){
            if (col == row || col == row + 4){
                cout << x ;
                x++;
            }
            else
                cout << " ";

        }

        cout << " \n" <<endl;
    }



    int y;
    y = 1;
    char b = 'A';


    for (row = 1; row <4; row++){
        for (col = 1; col <6; col++){
            if (row == col || col == (5 + 1) - row){
                cout << y;
                y++;
            }
            else
                cout << " ";
        }
        cout << endl;
    }

    for (row = 1; row < 2; row++){
        for (col = 1; col < 6; col++){
            if (col == row + 1 || col == row + 3){
                cout << b;
                b++;
            }

            else
                cout << " ";
        }

        cout << endl;
    }

    for (row = 1; row < 2; row++){
        for (col = 1; col < 6; col++){
            if (col == row || col == row + 4){
                cout << b;
                b++;
            }
            else
                cout << " ";
        }
        cout << endl;
    }

    cin.get();
    return 0;
}

Edited 1 Year Ago by Hector3000

A   B         1   2
 C D           3 4
  E             5
 1 2           A B
3   4         C   B

Edited 1 Year Ago by Hector3000

You have written too much code that doesn't do what's needed working. Bin it. Start again, and take each requirement in turn. I can see that some parts of it you have no idea about; you're just guessing at code to write (
int choice1, choice2, choice is completely useless and clearly just you guessing). Programming is about thinking; you cannot program by guessing.

Do just this bit: User must keyed-in "start" to start the program

If you can't do that, say so and we will tell you how to fetch input from the keyboard. If you can do that, get it working and then move on to the next step.

Edited 1 Year Ago by Moschops

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