Is it possible to solve this problem in c++?

Write a program that counts the numbers from 3 to 117. But for multiples of three add 3 instead of 1 and for the multiples of five add 5 instead of 1. For numbers which are multiples of both three and five add 15 instead of 1. Ex: If we are looking at numbers 5 to 15 (inclusive), the program would output 39.

## Recommended Answers

Jump to PostYou will need a for loop and an understanding of modulus, and a little bit of good old fashioned logic.

Good luck!

Jump to PostWell if

`X % 3`

is zero then you know X is divisible by 3.

Jump to Postwhen something is evenly divisible by a number the modulo is 0.

`15 / 3 = 5 15 % 3 = 0`

Knowing this you can write the following code to see if something is divisble by a number:

`if(someNUmber % 3 == 0) the number is …`

Jump to Post`x<=i<=y`

Is not valid c++. If you need to loop between all number in x and y then you can use:

`for (int i = x; i <= y; i++)`

Wich is translated to: start with

`i`

equall to`x`

and loop while`i`

is less …

Jump to PostWhat did you plug in for the missing values and what does your for loop look like now? Remember when you are doing the summation that if the number is divisible by 15 you add 15, if it is divisible by 5 you add 5, if it is divisible by …

## All 23 Replies

Maritimo
15
Junior Poster in Training

ryantroop
177
Practically a Master Poster

ivel
0
Newbie Poster

ddanbe
2,724
Professional Procrastinator
Featured Poster

NathanOliver
429
Veteran Poster
Featured Poster

ivel
0
Newbie Poster

ivel
0
Newbie Poster

Henry Mark
0
Newbie Poster

ivel
0
Newbie Poster

NathanOliver
429
Veteran Poster
Featured Poster

ivel
0
Newbie Poster

ivel
0
Newbie Poster

NathanOliver
429
Veteran Poster
Featured Poster

ivel
0
Newbie Poster

NathanOliver
429
Veteran Poster
Featured Poster

sneekula
969
Nearly a Posting Maven

ddanbe
commented:
Nice
+15

ivel
0
Newbie Poster

NathanOliver
429
Veteran Poster
Featured Poster

David_50
13
Junior Poster in Training

sneekula
969
Nearly a Posting Maven

ivel
0
Newbie Poster

Nimra_1
0
Newbie Poster

NathanOliver
429
Veteran Poster
Featured Poster

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.