Question

In: Computer Science

Directions: Convert the following problems below to c++ equivalent Problem 2: Enter a random number Store...

Directions: Convert the following problems below to c++ equivalent

Problem 2:

  1. Enter a random number
  2. Store the original number for later use
  3. Multiply the number by 3
  4. Add 45 to the number
  5. Multiply the number by 2
  6. Divide the number by 6
  7. Subtract the original number from your previous answer
  8. The result should be 15

Solutions

Expert Solution

Program code to copy

#include <iostream>
using namespace std;

int main(){
  
int num, num_copy;

//Taking integer input
cout<<"Enter a number: ";
cin>>num;
  
//Applying constraint according to question
//Storing number
num_copy = num;
  
//Multiplying number by 3
num = num*3;
  
//Adding 45 to number
num = num + 45;
  
//Multiplying the number by 2
num = num * 2;
  
//Dividing the number by 2
num = num / 6;
  
//Subtracting the original number from answer
num = num - num_copy;   
  
cout<<"Value after operations: "<<num;
  
return 0;
}

Program Screenshot with different inputs and outputs

Code is working for negative number also

Checking for large inputs


Related Solutions

Directions: Convert the following problems below to c++ equivalent code Problem 3: Take any 2 digit...
Directions: Convert the following problems below to c++ equivalent code Problem 3: Take any 2 digit number from 31 to 99. (You do not have to check the numbers just assume the user will enter a valid number so long as you tell them to). Store an extra copy of this number for later 3.   Add 82 to the number. 4.    Remove the hundreds place from your number 5.    Add 1 to the number. 6.    Subtract this from your...
Problem: Convert the following binary number to decimal. 1. 110101.101 Problem: Convert the following decimal number...
Problem: Convert the following binary number to decimal. 1. 110101.101 Problem: Convert the following decimal number to fractional binary representation. 1. 103.5625
Problem A) Convert the equation x^2 + y^2 = 4z^2 into cylindrical coordinates. Problem C) Use...
Problem A) Convert the equation x^2 + y^2 = 4z^2 into cylindrical coordinates. Problem C) Use cylindrical coordinates to find the volume of the region above the paraboloid z = x^2 + y^2 and inside the sphere x^2 + y^2 + z^2 = 6.
Directions: Solve the following problems, detailing and documenting the solutions. Additional instructions: For each problem, be...
Directions: Solve the following problems, detailing and documenting the solutions. Additional instructions: For each problem, be sure to include the (a) type of parametric or nonparametric testing being performed; (b) both null and research hypotheses; (c) critical value and test statistic; (d) p-value; and (e) both technical and contextual conclusions. 1. The back offices for the five department stores that anchor Pinelands Promenade Mall dispute whether or not they receive comparable treatment by mall management. In response, mall management hired...
write a VBA code to convert an arbitrary positive binary fractional number (0< number<1) to equivalent...
write a VBA code to convert an arbitrary positive binary fractional number (0< number<1) to equivalent decimal number. the code should acquire the binary fraction number in the format"0.xxxxxx"from input box, then return the equivalent decimal number in a message box. in the code, you may need to use VBA function "mid(_,_,_)" to pick up a specific symbols or characters from a string. you can use below conversion as benchmark to verify and debug your code: (0.1011)2 = (0.6875)10   
Write in C++ Example Enter number of miles travelled 12340 Enter number of hours in trip...
Write in C++ Example Enter number of miles travelled 12340 Enter number of hours in trip 460 file.txt Miles: 12340 Hours: 460 MPH: 26.83 Question: Write a program that does the following things: 1 ) Ask the user for number of miles travelled (should be in getData function and number of hours in trip (should be in getData function) [Note: Use reference parameters to have access to these values in main] 2 ) Calculate the miles per hour(MPH) for the...
In C program. Read and convert a sequence of digits to its equivalent integer. Any leading...
In C program. Read and convert a sequence of digits to its equivalent integer. Any leading white space should be skipped. The conversion should include digit characters until a non-digit character is encountered. Modify the program so it can read and convert a sequence of digit characters preceded by a sign, + or -.
Take the Java program Pretty.java and convert it to the equivalent C program. You can use...
Take the Java program Pretty.java and convert it to the equivalent C program. You can use the file in.txt as sample input for your program. v import java.io.*; import java.util.*; public class Pretty { public static final int LINE_SIZE = 50; public static void main(String[] parms) { String inputLine; int position = 1; Scanner fileIn = new Scanner(System.in); while (fileIn.hasNextLine()) { inputLine = fileIn.nextLine(); if (inputLine.equals("")) { if (position > 1) { System.out.println(); } System.out.println(); position = 1; } else...
Digital arithmetic: a) Convert +35 to 2-complement b) Convert -35 to 2-complement c) Convert 2-complement from...
Digital arithmetic: a) Convert +35 to 2-complement b) Convert -35 to 2-complement c) Convert 2-complement from 1101 1101 to decimal d) Add 35 - 35 in binary
Code in C-language programming description about convert binary number to decimal number.
Code in C-language programming description about convert binary number to decimal number.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT