Pseudocode

I am trying to get the Main module to this question and how to input the validation but I am lost. I will show you the solution I did but it is still missing input validation and the main module confuses me. I am more worried about the pseudocode more than the flowchart. I believe I understand how to do the flowchart.
Here is the question:
Maximum of three integers
Your task is to design a program that will find maximum of three positive integers.
You should do input validation. Make sure that users enter a positive numbers.
You will have a main module and a function named max that accepts three integer values as arguments. The max function should return the value that is greater of the three. For example, if 7,12 and 9 are passed as arguments to the function, the function should return 12.
You should submit pseudocode and flowchart. In a MS Word file, please copy and paste the following statement and put your initials to the bottom of the statement.

My Answer:

Module Main()
Declare Integer num1, num2, num3
Display "Enter num1 is", num1
Input num1
Display "Enter num2 is", num2
Input num2
Display "Enter num3 is", num3
Input num3
Set number = maximum
End Module

While number <= max
Set maxNumber = number
Display "The maximum number is", number
End While

Function Integer max (Integer num1, Integer num2, Integer num3)
Declare Integer max
Set max = num1
If max < num2 then
Set max = num2
End if
If max < num3 then
Set max = num3
End if
Return max
End Function

Can someone please check it and stir me the right way. Thank you.



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
#include <iostream>

using namespace std;

double maxNumber(double num1, double num2, double num3)
{
	double maximum = num1;
	if(num2 > maximum) maximum = num2;
	if(num3 > maximum) maximum = num3;

	return maximum;
}

int main()
{
	double num1;
	double num2;
	double num3;

	cout << "+ Enter number 1 : "; cin >> num1; 
	cout << "+ Enter number 2 : "; cin >> num2;
	cout << "+ Enter number 3 : "; cin >> num3; cin.ignore();

	cout << "The maximum number of the three numbers : " << maxNumber(num1, num2, num3) << endl;
	cout << "The program has ended. Press any key to continue. . .";
	cin.get();
	return 0;	
}

+ Enter number 1 : 22
+ Enter number 2 : 67
+ Enter number 3 : 444
The maximum number of the three numbers : 444
The program has ended. Press any key to continue. . .


Not exactly what is in your pseudo-code, you can choose to adapt the code to your needs.
Last edited on
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
Function Integer max : parameters Integer num1, Integer num2, Integer num3

    Declare Integer max
    Set max = num1
    
    If max < num2 then
        Set max = num2
    End if
    
    If max < num3 then
        Set max = num3
    End if

    Return max

End Function max



Function Main

    Declare Integer num1, num2, num3
    
    Input1:
        Display "Enter num1: "
        Input num1
        If num1 < 1
            Display "enter a positive integer: " 
            Repeat from step Input1
        End If       
    
    Input2:
        Display "Enter num2: "
        Input num2
        If num2 < 1
            Display "enter a positive integer: " 
            Repeat from step Input2:
        End If       
    
    Input3:
        Display "Enter num1: "
        Input num3
        If num3 < 1
            Display "enter a positive integer: " 
            Repeat from step Input3:
        End If     
        
    Comment 
        Note that Input1, Input2 and Input3 can be factored into a single function 
    End Comment         
    
    Declare integer max_number
    Call Function max with num1, num2, num3 as arguments
    Store the value returned by the function in max_number
    
    Display the value of max_number
     
End Function main
@JLBorges
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  Input1:
        Display "Enter num1: "
        Input num1
        If num1 < 1
            Display "enter a positive integer: " 
            Repeat from step Input1
        End If       
    
    Input2:
        Display "Enter num2: "
        Input num2
        If num2 < 1
            Display "enter a positive integer: " 
            Repeat from step Input2:
        End If       
    
    Input3:
        Display "Enter num1: "
        Input num3
        If num3 < 1
            Display "enter a positive integer: " 
            Repeat from step Input3:
        End If


Should be :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  Input1:
        Display "Enter num1 : "
        Input num1
        If num1 < 1
            Display "enter a positive integer: " 
            Repeat from step Input1
        End If       
    
    Input2:
        Display "Enter num2 : "
        Input num2
        If num2 < 1
            Display "enter a positive integer: " 
            Repeat from step Input2:
        End If       
    
    Input3:
        Display "Enter num3 : "
        Input num3
        If num3 < 1
            Display "enter a positive integer: " 
            Repeat from step Input3:
        End If

It is unusual to see you make mistakes, to be honest.
It is unusual to see you make mistakes, to be honest.

On the other hand, it is quite typical to see you nitpicking others "errors" and responding condescendingly.

The fact that you quoted his entire pseudocode to correct a simple typo in a single word is quite sad and just screams, "Look at me! See how superior I am for correcting JLBorges!"
Last edited on
Topic archived. No new replies allowed.