Question

I do not know where to begin with this code Using C++ code, write a program...

I do not know where to begin with this code

Using C++ code, write a program to print "R" if 2 random integers A and b in the range [-80,  

80] are both positive, "L" if A and B are both negative and "Z" otherwise.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The Program is given below with proper comments, also see the screen shots for code and sample results for more clarity:

Code

 #include<iostream> #include <cstdlib> using namespace std; int main() { //Declare integers int a,b; //Input any two integers in the range [-80,80] cout<<"Enter value for a: "; cin>>a; cout<<"\nEnter value for b: "; cin>>b; //check whether the input belongs to the required range [-80,80] while(abs(a)>80 || abs(b)>80) { //Display errors cout<<"Invalid inputs enter any two numbers in the range [-80,80]"<<endl; //Input any two integers in the range [-80,80] cout<<"Enter value for a: "; cin>>a; cout<<"\nEnter value for b: "; cin>>b; } //print "R" if a and b are positive if(a>0 && b>0) { cout<<"R"<<endl; } //print "L" if a and b are negative else if(a<0 && b<0) { cout<<"L"<<endl; } //Otherwise print "Z" else { cout<<"Z"<<endl; } return 0; }

Screen shot for source code

#include<iostream> #include <cstdlib> using namespace std; int main() { //Declare integers int a,b; //Input any two integers

Sample outputs

Enter value for a: 10 Enter value for b: 20 R damsas@damsas-HP-Laptop-15-da0xxx:-/Chegg/June$ ./a.out Enter value for a: -10

Add a comment
Know the answer?
Add Answer to:
I do not know where to begin with this code Using C++ code, write a program...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • write the solution of the program by python 3 language : I need the program using...

    write the solution of the program by python 3 language : I need the program using list or string or loops (while and for) or if,elif,else : You are given a sequence of n non-zero integers a1,a2,…,an. Determine if the given sequence contains a pair of adjacent elements of the same sign (both negative or both positive). Two elements are called adjacent if they stand next to each other in the sequence. Input The first line contains an integer n...

  • write the solution of the program by python 3 language : I need the program using...

    write the solution of the program by python 3 language : I need the program using list or string or loops (while and for) or if,elif,else : i have 15 min to submit the solution please help me   You are given a sequence of n non-zero integers a1,a2,…,an. Determine if the given sequence contains a pair of adjacent elements of the same sign (both negative or both positive). Two elements are called adjacent if they stand next to each other...

  • Write a program in C using the fork() system call to do the following. The parent process (main program) forks a process...

    Write a program in C using the fork() system call to do the following. The parent process (main program) forks a process (CHILD 1) to compute and print the sum of first n integers where n is a variable shared between the parent and CHILD 1. It also forks another process (CHILD 2) that finds the sum of squares of the first n numbers where n is a variable it shares with the parent. Let CHILD 1 print “The sum...

  • Write a C program that accepts a single integer N. Your code must then calculate the...

    Write a C program that accepts a single integer N. Your code must then calculate the average of all positive integers less than N that are divisible by either 5 or 7, but not both. When you print your average, truncate the result to three decimal places. Do not print anything else to the screen. Example input: 19 Example output: 10.200

  • Write a program in C that meets the following requirements: 1. Your program will read n...

    Write a program in C that meets the following requirements: 1. Your program will read n + 1 integers from the keyboard where n is the first integer read. 2. If n is less than 1 print an error message and return a status of 1. 3. If there are no positive numbers, print “no positive numbers”. This is not an error. 4. If there are positive numbers, print the average of the positive numbers. 5. 0 is neither positive...

  • Java Programming - Write a program that generates two random integers, both in the range 25...

    Java Programming - Write a program that generates two random integers, both in the range 25 to 75, inclusive. Use the Math class. Print both integers and then display the positive difference between the two integers, but use a selection. Do not use the absolute value method of the Math class.

  • Write an assembly language program to do the following, and run it and test it on...

    Write an assembly language program to do the following, and run it and test it on the lab simulator: Read in integers until a zero is read in. Keep a total of both the quantity and the sum of the negative integers and the positive integers. Once a zero is read in (signifying the end of the input) then: • If there were more positive than negative integers, or an equal number, print out a 0 and the sum of...

  • write the program with the language NODEJS need help Programming challenge, screenshot your work and output.  ...

    write the program with the language NODEJS need help Programming challenge, screenshot your work and output.   Description A positive integer is a palindrome if its decimal representation (without leading zeros, is a palindromic string (a string that reads the same forwards and backwards). For example, the number 5, 77, 363, 4884, 11111, 12121 and 349943 are palindromes A range of integers is interesting if it contains an even number of palindromes. The range [L, R], with L <= R, is...

  • Write a section of Java code using while, do-while and for loops Write a section of...

    Write a section of Java code using while, do-while and for loops Write a section of Java code that will print out random integers between 1 and 100 while N is less than or equal to 5. Sample output > random # 1 is: 73 random # 2 is: 68 random # 3 is: 76 random # 4 is: 64

  • Write a program using the fork() system call to do thefollowing. The parent process (main program)...

    Write a program using the fork() system call to do thefollowing. The parent process (main program) forks a process(CHILD 1) to compute and print the sum of first n integers where n is a variable shared between the parent and CHILD 1. Have the parent invoke the wait () call to wait for both the child processesto complete before exiting the program. IN A C program

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT