+1

What loops would you use for finding arithmetic sequences in time?

So here's a homework problem that I'm a little stumped on... Let's say that you have a digital clock that doesn't display leading zeros in the hour time (so it would be 5:04 instead of 05:04). You are trying to create a program in which finds out the number of different arithmetic sequences between 12:00, and another user specified time. Arithmetic sequence - a series of numbers (in this case 3 for 4) that increment or decrement evenly Example - 1 2 3 4 or -5 -10 -15 -20 or 4 7 10 13 For example... If I wanted to find all the arithmetic sequences between 12:00 and 12:34, well then there'd only be one, 12:34 (notice how each number goes up by one). If I were to find all the arithmetic sequences between 12:00 and 1:35, then there'd be 4: 12:34, 1:11, 1:23, and 1:35. -------------------------------------------------------------------------------------------------------------- Example input (in minutes): 180 Example Output: 12:34 1:11 1:23 1:35 1:47 1:59 2:10 2:22 2:34 2:46 2:58 Explanation of Output: We start at the time 12:00, and have to find all the arithmetic sequences up to the time 3:00 (12:00 + 180 minutes = 3:00). The the rest is just straight forward. -------------------------------------------------------------------------------------------------------------- I have a basic sketch of the problem, but I can't seem to work out the pointer conversions. Whenever I run this code, it's doesn't give me any output. int startingTime = 1200; int *currentTime = &startingTime; int increment = 1; int userInputedTime; cin >> userInputedTime; // converts to 24 hour time for easier usage userInputedTime = userInputedTime / 60 * 100 + 1200; int *userInputedPointer = &userInputedTime; while (currentTime < userInputedPointer) { currentTime += increment; if (currentTime[1] - currentTime[0] == currentTime[2] - currentTime[1] == currentTime[3] - currentTime[2]) cout << currentTime << endl; incr

8/25/2019 5:19:31 PM

Fuzzy Squid

1 Answer

New Answer

+1

Read on iterative control structures.. also look into recursion concepts.. Good luck