![]() |
|
#1
|
|||
|
|||
StuckSorry just stuck on this quesiton. this is the question and below is what ive done so far, dont know how to do a calculation that would add the purposed values.
For this question create two files called A2Part3.txt and A2Part3.cpp. Write a program that asks the user to enter a positive integer value. The program should use an iterative control structure (loop) to get the sum of all integers from 1 up to and including the number entered, excluding: - All numbers that are wholly divisible by 3. - All even numbers that are less than or equal to 10. For example, if the user enters 50, the program should compute 1 + 5 + 7 + 11 + 13 + 14 + 16 + … + 50. If the input provided by the user is a negative number or 0, then your program merely displays an appropriate error message. The following shows 2 sample interactions with the program. CPP / C++ / C Code:
|
|||
|
#2
|
|||
|
|||
Re: Stuckso once you know num, you can create a for loop that will count up from one to num. keep a variable (defined outside the loop) that will hold your total. each time through the loop, check whether the counter is divisible by three (use the modulus operator) or whether it is even and <= 10. Otherwise, add it to the total.
CPP / C++ / C Code:
|
|
#3
|
|||
|
|||
Re: StuckThis is what i got but dont work, it makes sense what your saying to me but trying to put that into hard code, is where im strugging.
CPP / C++ / C Code:
|
|
#4
|
|||
|
|||
Re: StuckGot this much now.
CPP / C++ / C Code:
|
|
#5
|
||||
|
||||
Re: StuckQuote:
You almost have it. What if does that else refer to? __________________
The 3 Laws of the Procrastination Society: 1) Never do today that which can be put off until tomorrow 2) Tomorrow never comes |
Recent GIDBlog
Vista ?Widgets? on Windows XP by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Missing or corrupt ntfs.sys | crassbones | Computer Software Forum - Windows | 27 | 13-Nov-2007 13:48 |
| stuck on Structs | eleet | C Programming Language | 14 | 14-Apr-2005 15:42 |
| Define Functions | Nexa | C Programming Language | 6 | 16-Nov-2004 10:58 |
| RSA program | fwongmc | C Programming Language | 11 | 08-Nov-2004 23:15 |
| C++ sums and average | homz | C++ Forum | 35 | 16-May-2004 17:35 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The