473,909 Members | 4,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
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 4077
dev7060
645 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
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 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

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

Similar topics

7
1415
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 numbers) on a plane between X and Y, saw 0,0 and 10,10? I can get my code to write the basics from 0-10 with a while loop, but only for 1 axis. #include<iostream>
2
2232
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 set to a different php script, which is responsible for returning a true/false (+ mesage back to the form. So I have something like this: <div id = "page1"><form onaction = "step1.php" method="post">...</form></div>
0
10035
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9877
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11346
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10919
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8097
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7248
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6138
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4774
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3357
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.