Question

Directions: Convert the following problem below to c++ equivalent code Problem 5: Take a random number...

Directions: Convert the following problem below to c++ equivalent code

Problem 5:

  1. Take a random number from the user
  2. Multiply the number by 4
  3. Add 1 to the number
  4. Multiply by the original number that the user input
  5. Subtract the original number away
  6. Take the square root of the number (you can use cmath’s sqrt function)
  7. Divide the number by 2
  8. The result should be the original number

Problem 8:

For this problem I want you to draw out a flow chart to illustrate the logic. You may use word, DIA, or any other software you choose but be specific on the symbols used to illustrate this problem. If you use hand drawn, make sure the paper is unlined and that your picture of it is clear and legible. Please submit this problem as an image file

  1. Take any random 2 digit number
  2. Divide the number by 2
  3. Add 17 to the number
  4. If the first digit (10’s place) of the number is greater than the last than add the first digit to the number, otherwise add the second digit (1’s place)
  5. If the number is greater than 21 subtract the product of the 2 digits.
    1. Repeat this until the number is less than 21
  6. Output the results of the number

Homework Answers

Answer #1

PROBLEM 5

C++ PROGRAM

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
   int n,x;;
   cout<<endl<<"Enter a number";
   cin>>n;
   x=n;//assign the user entry number to x
   x=x*4; //multiply x by 4
   x=x+1;//add 1 to x
   x=x*n;//multiply x by user entry number
   x=x-n;//subtract the user entry number from x
   x=sqrt(x); //find the square root of x
   x=x/2;//devide x by 2
   if(x==n) //check whether x and n equal or not. The result will always will be trur
   cout<<endl<<"Equal";
   else
   cout<<endl<<"Unequal";
}

OUTPUT

PROBLEM 8

FLOWCHART USING FLOWGARITHM

OUTPUT

FLOWCHART INLARGE SIZE

C++ PROGRAM

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
   int x,a,b;;
   do
   {
           cout<<endl<<"Enter a number";
   cin>>x;//input the number
   }while(x<10 || x>99);//check for 2 digit or not

  
   do
   {
   x=x/2;//devide by 2
   x=x+17;//add 17
   a=x %10;//find the unit place digit
   b=x/10;//find the 10's place digit
   if(b>a) //compare b with a and do the necessary action
   x=x+b;
   else
   x=x+a;
   if(x>21) //check whether the number greater to 21 or not
   x=x-(a*b);   //subtract (a*b)if greater to 21
   }while(x<21);//continue the process till the number less than 21
   cout<<endl<<"nUMBER IS "<<x;//display the number
}

OUTPUT

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Directions: Convert the following problems below to c++ equivalent code Problem 6: Get a random number...
Directions: Convert the following problems below to c++ equivalent code Problem 6: Get a random number from the user Remember the original number Add 3 to the number Double the number and then multiply by Knock off the last digit (remove the 1’s place) Finally remove the original number What is the result? Problem 7: 1: Have the person write down any three digits number with decreasing digits (432 or 875). 2: Reverse the number you wrote in #1. 3:...
Problem: Our Armstrong number Please write code for C language So far we have worked on...
Problem: Our Armstrong number Please write code for C language So far we have worked on obtaining individual digits from 4 digits or 5 digit numbers. Then added them to find the sum of digits in various examples and assignments. However, the process of extracting individual digits is actually can be solved using a loop as you were doing a repetitive task by using mod operation and division operation. Now, we know how loops work and we can remove the...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts,...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts, it will present a welcome screen. You will ask the user for their first name and what class they are using the program for (remember that this is a string that has spaces in it), then you will print the following message: NAME, welcome to your Magic Number program. I hope it helps you with your CSCI 1410 class! Note that "NAME" and "CSCI...
I want you to calculate a random number of calorie intake using both ways You can...
I want you to calculate a random number of calorie intake using both ways You can calculate your calorie intake by using the calorie chart. A calorie chart is a chart which tells you about the calorie which you took for a certain amount of food. You can get calorie chart on internet,for ex: Now by using it calculate how much calorie you take in. OR Step 1- find out your calorific baseline,or your weight. Step2-multiply by 11 Step 3-...
Subject- ( App Development for Web) ( language C#, software -visual studio) Exact question is-Firstly the...
Subject- ( App Development for Web) ( language C#, software -visual studio) Exact question is-Firstly the console calculator is created which perform multiply,divide,sub and add, operation and it accept all type of data (divide by 0 case as well ).Now the main motive is to create the library project from the console calculator project .Than we have to create a unit test project which test the functionality of added library.Make test like Test 1. multiply two positive number,Test 2. Add...
I am to create three different versions of the following C program code below that implements...
I am to create three different versions of the following C program code below that implements the conversion of unsigned binary numbers into decimal (Base 2 to Base 10 conversion). Version 1: Complete the C program ”bin2dec ver1.c” that implements binary to decimal conversion. The maximum number of binary bits is 32. The program is made of the functions ”unsigned binary to decimal(const char *str)”and ”main”. The parameter ”str” passed to this function points to a C string comprising only...
write a code in python Write the following functions below based on their comments. Note Pass...
write a code in python Write the following functions below based on their comments. Note Pass is a key word you can use to have a function the does not do anything. You are only allowed to use what was discussed in the lectures, labs and assignments, and there is no need to import any libraries. #!/usr/bin/python3 #(1 Mark) This function will take in a string of digits and check to see if all the digits in the string are...
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input...
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input operator>> a bigint in the following manner: Read in any number of digits [0-9] until a semi colon ";" is encountered. The number may span over multiple lines. You can assume the input is valid. Overload the operator+ so that it adds two bigint together. Overload the subscript operator[]. It should return the i-th digit, where i is the 10^i position. So the first...
The Problem Write a C or C++ program which performs specific operations on bits. The user...
The Problem Write a C or C++ program which performs specific operations on bits. The user will specify a value The user can then set, test, or toggle individual bits in the initial value. Input Your program will prompt the user for: An inital value in hexadecimal. This value may be up to 32 bits (eight hexadecimal digits) long. If the user-supplied value is less than eight characters in length, assume the additional digits are zero and are on the...
C Programming: I am working on the problem below and have got all of the code...
C Programming: I am working on the problem below and have got all of the code down, except for one part I can't figure out. The logic for the calculation where the the total at each shop is giving after each iteration of the loop. this is the formula I've got: ingredientPrice += ingredient1; It calculates the total for the first shop properly, but for the shops that follow it gives a cumulative total rather than the singular total for...