Question

Hello, I need some help with a program in C++, the thing is that i need...

Hello,

I need some help with a program in C++, the thing is that i need to subtract 7 from a Number(R) given until that number is between 0 and 6.

Example

R=20

20-7=13

13-7=6 then stop here

R=30

30-7=23

23-7=16

16-7=9

9-7=2 then stop here.

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

//PROGRAM with comments STARTS HERE

#include<iostream>

using namespace std;

#define SUB 7

int main(){

int R; //variable R to store input number

cout << "Enter R : "; //Prompt user to Enter R

cin >> R; // storing input to R

bool stop = false; // variable to control while loop

cout << endl << "R=" << R << endl; // output value of R

int rem = R; //variable to store remaining value after substraction (initialize it with value of R)

while(!stop){ // start of while loop (runs till stop is true)

if(rem >= 0 && rem <= 6){ //cheking if rem is between 0 and 6

stop = true; //if above condition is true, set stop to false

continue; // and skip the rest of the loop statements (printing to console)

}

cout << rem << "-" << SUB << "=" << rem - SUB << endl; //this line prints to the console

rem = rem - SUB; //update remaining value by subtracting 7

}

}

//PROGRAM ENDS HERE

//SCREENSHOTS:

1. PROGRAM

2. PROGRAM with Output

3. Compilation and executions (and output) :

Add a comment
Know the answer?
Add Answer to:
Hello, I need some help with a program in C++, the thing is that i need...
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
  • I need some help with Java. I need to write a Java program that generates a...

    I need some help with Java. I need to write a Java program that generates a set of random strings from a given string of same length where no character is ever repeated and character belong to the original string. See example. Example Input: “Hello World” (length 9) Output: “World oHlel” (length 9)

  • Hello Sir, I need help with Java. Here is the problem below. Problem 1.Write a program...

    Hello Sir, I need help with Java. Here is the problem below. Problem 1.Write a program that prompts the user to enter the number of milliseconds and converts the milliseconds to a string hours:minutes:seconds. The program should use the convertMillismethod with the following header: public static String convertMillis(long millis) For example, convertMillis(5500) returns the string 0:0:5, convertMillis(100000) returns the string 0:1:40, and convertMillis(555550000) returns the string 154:19:10. Problem 2. (Count occurrence of numbers)Write a program that reads integers between 1...

  • Hello, I need help with the following C code. This program asks the user to enter...

    Hello, I need help with the following C code. This program asks the user to enter three numbers and outputs the sum on the screen , all im trying to do is have the program reprompt the user for a number if anything other than a number is entered for each of the entries. I wanted to use do while for each of the functions but that did not work for example: Enter Number 1: 2 Enter Number 2: Hello...

  • PYTHON I need some basic python homework help! Write a program that prompts the user to...

    PYTHON I need some basic python homework help! Write a program that prompts the user to enter a date (day, month, and year). Your program will print out the day of the week for that date. You do not need to validate the input. That means you can assume: the year will be entered as a four-digit number in the range 1900 through 2100 inclusive. the month will be one of the strings "January", "February", . . ., "December". the...

  • I need help building a program on microsoft visual studio using c++ language. implement a program...

    I need help building a program on microsoft visual studio using c++ language. implement a program called "charword_freq.cpp" to determine the number of words and the number of occurrences of each letter in a block of text stored in a data file called “mytext.dat”. Define a word to be any string of letters that is delimited at each end by either whitespace, a period, a comma, or the beginning or end of a line. You can assume that the input...

  • I need help in C++ assignment. please add statements and i am Xcode complier user. Requested...

    I need help in C++ assignment. please add statements and i am Xcode complier user. Requested files: CountDecades.cpp (Download) Maximum upload file size: 96 KiB Write a C++ program named CountDecades.cpp. In this program you will have two integer arrays. One named inputArray of size 20 containing the values: 83, 2, 23, 11, 97, 23, 41, 67, 16, 25, 1 , 4, 75, 92, 52, 6, 44, 81, 8, 64 in the order specified, and an empty integer array of...

  • I know is this posted else where BUT I NEED HELP IMPLEMENTING THE TIME DELAY!!!! I...

    I know is this posted else where BUT I NEED HELP IMPLEMENTING THE TIME DELAY!!!! I need a source comment next to the line that gives the delay so i can compare please. (Concurrency – Semaphores) 1.- In this assignment you will implement a deadlock free variant of the bounded-buffer producer/consumer using jBACI (C - -). C- - is a subset of C + + that allows you to declare semaphores and apply the operations P and V. In the...

  • Hello I need help with this. I am trying to use JOptionpane to ask 5 questions....

    Hello I need help with this. I am trying to use JOptionpane to ask 5 questions. However I cannot get the program to do anything after an initial selection is made. Here is the assignment. Write an application that creates a quiz, which contains at least five questions about a hobby, popular music, astronomy, or any other personal interest. Each question should be a multiple choice question with at least three options. When a user answers a question correctly, display...

  • NEED SOME HELP WRITING THIS C++ PROGRAM...so far I wrote this program for (r-1; r <-5;...

    NEED SOME HELP WRITING THIS C++ PROGRAM...so far I wrote this program for (r-1; r <-5; r++) output for (r = 1; r<= 5; r++) output NEED HELP WITH THIS PATTERN:

  • Hello, i need some physics help! The drawing shows a graph of the angular velocity of...

    Hello, i need some physics help! The drawing shows a graph of the angular velocity of a rotating wheel as a function of time. Although not shown in the graph, the angular velocity continues to increase at the same rate until t = 10.0 s. What is the angular displacement of the wheel from 0 to 10.0 s?

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