473,567 Members | 2,909 Online

# Pesudocode to C++

1 New Member
Hi, I need help in converting the pesudocode into c++ code.

Initialize key = ROLLNO, extra = NAME_POSITION
Start the iterator with value 1
If the iteration number is greater than 5, go to step 12
if the ROLLNO is greater or equal to 50
subtract 2 from extra
go to step 6
Otherwise
Double the value of key
Go to step 8
If the ROLLNO is greater than 74
Multiply the extra by 2
Go to step 10
Otherwise
Subtract extra from key
Go to step
If ROLLNO is less than 25
Divide key by 3
Go to step 10
Otherwise
Add 6 to both key and extra
Go to step 10
Go to step 3
Output key, extra
Stop
Jan 3 '23 #1
2 4045
dev7060
639 Recognized Expert Contributor
Hi, I need help in converting the pesudocode into c++ code.

Initialize key = ROLLNO, extra = NAME_POSITION
Start the iterator with value 1
If the iteration number is greater than 5, go to step 12
if the ROLLNO is greater or equal to 50
subtract 2 from extra
go to step 6
Otherwise
Double the value of key
Go to step 8
If the ROLLNO is greater than 74
Multiply the extra by 2
Go to step 10
Otherwise
Subtract extra from key
Go to step
If ROLLNO is less than 25
Divide key by 3
Go to step 10
Otherwise
Add 6 to both key and extra
Go to step 10
Go to step 3
Output key, extra
Stop
What have you done so far?
Jan 4 '23 #2
BloomS
8 New Member
Expand|Select|Wrap|Line Numbers
1. // C++ Code
2.
3. int key = ROLLNO;
4. int extra = NAME_POSITION;
5.
6. for (int i = 1; i <= 5; i++) {
7.     if (ROLLNO >= 50) {
8.         key += 5;
9.         extra -=2;
10.     } else {
11.         key *= 2;
12.         extra += 3;
13.
14.         if (ROLLNO > 74) {
15.             key += 25;
16.             extra *= 2;
17.         } else {
18.             key += ROLLNO;
19.             key -= extra;
20.
21.             if (ROLLNO < 25) {
22.                 key /= 3;
23.                 extra += 4;
24.             } else {
25.                 key += 6;
26.                 extra += 6;
27.             }
28.         }
29.     }
30. }
31.
32. cout << key << " " << extra << endl;
Jan 4 '23 #3