Need Help with problem please!

I am trying to make a program that makes you choose a pattern and then a size and then print out that pattern based on what size the user has chosen. For choice one it has to print out a square with the length and width both whatever size the user has chosen, and then the size number has to be printed out diagonal left to right with all other characters being the '#' character. For example if the user has chosen choice 1 and size 4 it would print out
4###
#4##
##4#
###4
As of now I only have it print the correct size square but all characters are 4
Im also currently only working on choice one for now.
Sorry if this is confusing, I didn't really know how to explain well. Please help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>

using namespace std;

int main()
{
	int choice = 0, size, count;

	while (choice != 5)
	{
		cout << "Your options are:" << endl;
		cout << "	" << "1: A square with a left to right diagnol" << endl;
		cout << "	" << "2: A square with a right to left diagnol" << endl;
		cout << "	" << "3: A square that fills left to right" << endl;
		cout << "	" << "4: A square that fills right to left" << endl;
		cout << "	" << "5: Exit" << endl;
		cout << "Which Choice? ";
		cin >> choice;

			switch (choice)
			{
			case 1:
			{
				cout << "Please choose a size from 1-9: ";
				cin >> size;
				if (size < 1 || size > 9)
				{
					do
					{
					cout << "Invalid choice please try again";
					cin >> size;
					} while (size < 1 || size > 9);
				}
				else
				{
					for (int i = 0; i < size; i++)
					{
						for (int j = 0; j < size; j++)
						{
							cout << size;
						}
					cout << endl;
					}
				}
			}
			break;
			case 2:
			{

			}
			break;
			case 3:
			{

			}
			break;
			case 4:
			{

			}
			break;
			case 5:
				break;
			default:
				cout << "That is an invalid choice" << endl;
				break;
			}

	}
	return 0;
}
I've fixed your code to my liking and replaced your main loop with a better one.
All you have to do now is to change each output character in the cases.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>

using namespace std;

int main()
{
	int choice = 0;
	int size; 
	int count;
	char again;
    
    do {
	cout << "Your options are:" << endl;
	cout << "\t1: A square with a left to right diagonal" << endl;
	cout << "\t2: A square with a right to left diagonal" << endl;
	cout << "\t3: A square that fills left to right" << endl;
	cout << "\t4: A square that fills right to left" << endl;
	cout << "\t5: Exit" << endl;
	cout << "Which Choice? ";
	cin >> choice;
        cout << "Please choose a size from 1-9: ";
        cin >> size;
        
        if (size < 1 || size > 9) {
		cout << "Invalid choice please try again.\n" << endl ;
    	}
    		
    	for (int i = 0; i < size; i++) {
            for (int j = 0; j < size; j++) {
    		    cout << size;
    		}
    	    cout << endl;
        }
            
    	switch (choice) {
    		case 1: {
    			
    		}
    		break;
    		case 2: {
    
    		}
    		break;
    		case 3: {
    
    		}
    		break;
    		case 4: {
    
    		}
    		break;
    		case 5: {
    		
    		}
    		break;
    		default: {
    			cout << "That is an invalid choice" << endl;
    			break;
    		}
    	}
		
        cout << "\nWould you like to continue? (Y/N) ";
        cin >> again;
    	
    } while( again == 'Y' || again == 'y' );
    
	return 0;
}
Last edited on
The part about asking if they want to go again is not is not needed just because the assignment is just supposed to go again and then the user can exit if they choose. Also I am unsure of how you code works. Could you explain more about changing the output characters in the cases? Also sorry I'm fairly new to C++ and only just learning it.
Last edited on
Topic archived. No new replies allowed.