help with my assignment please...

So been trying to finish this assignment for weeks now and i only have a couple weeks left before i fail it. everything needs to be done locally. if anyone could help me do the menu? heres what its asking me to do


The standalone Console Application will:

• Provide an intuitive and easily navigable text based menu-driven interface allowing the user to navigate back and forth between options

The options to be provided are:

Option 1: To generate a personal username

Option 2: To calculate a number’s factorial

Option 3: To exit from the application

• The user is required to supply an appropriate numeric menu option at a QWERTY keyboard

• The user’s input will be checked and only the numbers 1 or 2 or 3 will be accepted as valid

• The following error message will be displayed if an invalid entry is given

“You entered an invalid menu choice, only the numbers ‘1’, ’2’ and
‘3’ are allowed, please press return and try again”

• When a valid menu option is provided, the user will be able to perform the associated task and will be prompted to return to the above menu when finished

• The program will continue to perform in this way until the user decides to terminate by entering the number 3


Menu Option 1 will:

• Offer the user the opportunity to generate a personal username based on the forename and surname provided

• NOT be required to perform any check of the validity of the user inputs

• Create a space-free username from the names provided by joining the surname to the initial (the first character of the forename)

e.g.
for a forename John and surname Craig entered, a username JCraig will be created


The Functional Requirements (continued)

Menu Option 2 will:

• Offer the user the opportunity to display the factorial of a whole number

“In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n”

e.g.
The factorial of 5 (represented mathematically as 5!) is calculated by multiplying 5 by 4 then by 3, then by 2 and finally by 1

5! = 5*4*3*2*1
= 120

Therefore
6! =6*5!
= 720

etc.

• NOT be required to perform any check of the validity of the input supplied


Menu Option 3 will:

• Offer the user the opportunity to quit the application whereby control will return back to the operating system



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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
 #include <iostream>

using namespace std;

void createusernamespec();
void displayfactorialspec();
void evalfactorialspec();
void getnames();
void getnumberspec();
void showusernamespec();
void menuspec();







void menuspec()

{
	cout << "Welcome to the EPOS Options Ltd.\n";
	cout << "Network Administration& Statistics Department’s\n";
	cout << "Pilot One Stop Shop interface\n\n\n";

	cout << "1 \t Create a username\n";
	cout << "2 \t Factorial a number\n";
	cout << "3 \t Exit\n";

	char usersChoice;
	do
	{
		menuspec();
		cout << "Please enter your choice:\n";
		cin >> usersChoice;

		switch (usersChoice)
		{
		case '1':
			cout << "Please enter your full name\n";
				system("pause");
			break;
		case '2':
			cout << "Enter a number to factorial\n";
				system("pause");
			break;
		case '3':
			cout << "This program will now quit\n";
			break;
		default:
			cout << "That was an invalid choice, please try again\n";
			break;
		}

	} while (usersChoice != '3' && usersChoice != '3');


}


void getnames()
{
	
	

}


void getnumberspec()
{

}

void createusernamespec()
{

}

void showusernamespec()
{

}

void evalfactorialspec()
{

}

void displayfactorialspec()
{

}

int main()
{
	
	menuspec();
	system("pause");
	return 0;

	
}
remove line 33 and I think your menu will work. You have called the same function inside itself; this is legal and called 'recursion' (and can be used for the factorial -- its a classic example of a way to use recursion, though a lookup table makes more sense to me). Recursion here is bad: it prints a few lines, calls itself, prints those lines again, calls itself... until it crashes.
you may want to read in the data after asking for it eg case 1.
you are doing different things in the cases, like getting a string (name) or a number (factorial). So likely you want this format:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
	
                case '1':
			cout << "Please enter your full name\n";
                        cin >> name; //get the data, handle the data
                        cout << "Welcome or something, " << name << endl;
				system("pause");
			break;
		case '2':
			cout << "Enter a number to factorial\n";
                        cin >> num;   //get the data, handle the data... see the pattern?
                        cout << "the factorial of  " << num <<" is "<< fact(num) << endl;
				system("pause");
			break;
	
Last edited on
Hello jjjohnny111,

There is no point to reiterate what jonnin has already said.

After reading the instructions a couple of times this is the way I take it:
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
#include <iostream>
#include <limits>
#include <string>  // <--- Needed for the fill ctor, (found in lines 10 and 16), and later for the "std::string" you will need.

void PrintHeadings()
{
    std::cout <<
        "Welcome to the EPOS Options Ltd.\n"
        "Network Administration& Statistics Department's\n"
        "Pilot One Stop Shop interface\n" << std::string(47, '-') << "\n";
}

void MainMenu()
{
    std::cout <<
        "\n                   MAIN MENU\n" << std::string(47, '-') << "\n"
        "1. Create a username\n"
        "2. Factorial a number\n"
        "3. Exit\n"
        " Enter choice: ";
}

int main()
{
    int menuChoice{};

    PrintHeadings();

    MainMenu();

    // <--- Get menu choice.

    // <--- Put the switch here.



    // A fair C++ replacement for "system("pause")". Or a way to pause the program.
    // The next line may not be needed. If you have to press enter to see the prompt it is not needed.
    //std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');  // <--- Requires header file <limits>.
    std::cout << "\n\n Press Enter to continue: ";
    std::cin.get();

    return 0;  // <--- Not required, but makes a good break point.
}

The "PrintHeadings" function is optional, but could be useful. You may not want to print the heading every time you print the menu.

As a note it is best when a function does 1 thing and returns or returns something.

Lines 37 - 41 is something I use when working on a program. It is safer than using "system" calls. When you are done either comment them all out or delete them.

Just as the functions should do 1 thing "main" should just direct the flow of the program. One reason for this is that when 3 is entered it makes it easier to end the program from "main".

jonnin's suggestion of writing the case statements will work.

I feel that this is a better start that follows the directions better. In the end you will have a better idea and better input from your class to know what to do.

Andy
For the simple menu starter, consider:

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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <iostream>
#include <limits>
#include <string>
#include <cctype>

int getInt(const std::string& prm = "")
{
	int i {};

	while ((std::cout << prm) && (!(std::cin >> i) || !std::isspace(std::cin.peek()))) {
		std::cout << "Not an integer\n";
		std::cin.clear();
		std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
	}

	std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
	return i;
}

using namespace std;

void createusernamespec();
void displayfactorialspec();
void evalfactorialspec();
void getnames();
void getnumberspec();
void showusernamespec();

void PrintHeadings()
{
	cout << "Welcome to the EPOS Options Ltd.\n";
	cout << "Network Administration & Statistics Department’s\n";
	cout << "Pilot One Stop Shop interface\n\n\n";
}

int Menu()
{
	cout << "1 \t Create a username\n";
	cout << "2 \t Factorial a number\n";
	cout << "3 \t Exit\n";
	cout << "Enter option: ";

	return getInt();
}

int main()
{
	PrintHeadings();

	do {
		switch (Menu()) {
			case 1:
				cout << "Please enter your full name\n";
				break;

			case 2:
				cout << "Enter a number to factorial\n";
				break;

			case 3:
				cout << "This program will now quit\n";
				return 0;

			default:
				cout << "That was an invalid choice, please try again\n";
				break;
		}
		//system("pause");

	} while (true);
}


void getnames()
{

}

void getnumberspec()
{

}

void createusernamespec()
{

}

void showusernamespec()
{

}

void evalfactorialspec()
{

}

void displayfactorialspec()
{

}


This just leaves the body of the functions to code - which is pretty straightforward.
Last edited on
Topic archived. No new replies allowed.