473,399 Members | 3,656 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Pesudocode to C++

1
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
add five to counter
subtract 2 from extra
go to step 6
Otherwise
Double the value of key
Add 3 to extra
Go to step 8
If the ROLLNO is greater than 74
Add 25 to the key
Multiply the extra by 2
Go to step 10
Otherwise
Add ROLLNO to the key
Subtract extra from key
Go to step
If ROLLNO is less than 25
Divide key by 3
Add 4 to extra
Go to step 10
Otherwise
Add 6 to both key and extra
Go to step 10
Add 1 to iterator
Go to step 3
Output key, extra
Stop
Jan 3 '23 #1
2 4008
dev7060
636 Expert 512MB
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
add five to counter
subtract 2 from extra
go to step 6
Otherwise
Double the value of key
Add 3 to extra
Go to step 8
If the ROLLNO is greater than 74
Add 25 to the key
Multiply the extra by 2
Go to step 10
Otherwise
Add ROLLNO to the key
Subtract extra from key
Go to step
If ROLLNO is less than 25
Divide key by 3
Add 4 to extra
Go to step 10
Otherwise
Add 6 to both key and extra
Go to step 10
Add 1 to iterator
Go to step 3
Output key, extra
Stop
What have you done so far?
Jan 4 '23 #2
BloomS
8 Nibble
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

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: pythonnoob | last post by:
Im new to programming, expecially c++. I started off in python but really just know the basics. My question is, how would i go about writing a program that would output all of the numbers (whole...
2
by: Ronald Raygun | last post by:
I have a form that I am using as a wizard. The wizard comprises of several forms contained in divs, which are hidden/made visible, depending on the wizard step. Each form has an action parameter...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.