Can't get the right answer

So I was trying to figure out why I get the wrong answer but I just can't.
There is a clock. The first day s he will be late 15 seconds. Next day s1 it will be more late than the previous time 25 seconds.
s1 = 15 seconds
s2 = 25 seconds
Then I have to input the number until when it will be late. So
Late = 15 minutes.
Just to make it easier I made Late *= 60 (so I get seconds)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  #include <iostream>

using namespace std;

int main()

{
    int s, s1, d, sum, late;

    cout << "Input number how much clock was late first day: \n";
    cin >> s;
    cout << "Input number how much it will be more late than the previous day: \n";
    cin >> s1;
    cout << "Input number until minutes it will be late: \n";
    cin >> late;



    d = 0; // starting from 0 days because I'll be looking how much days it will take for the clock to be late 15 minutes.
    late *= 60; // converting minutes into seconds.

    while (sum <= late) {

        s1 += s1;
        d += 1;
        suma = s1 + s;
    }

    cout << "15 mins clock will be late in: " << d << " days." << endl;


}


And for some reason I get 6 days as a answer. It should be 9 days.
Last edited on
Obviously English is not your first language, but you need to give a better description of the problem. I don't understand what you're saying.

If there is an online description (in English), link to it.

And please post real code. What you posted above doesn't even compile.
Last edited on
And for some reason I get 6 days as a answer. It should be 9 days.


Clock begins 15 seconds late. Day one.
Every subsequent day, it will be another 25 seconds late.

How many days until it is 900 seconds late?

On day 1, it will be 15 seconds late.
On day 2, it will be 40 seconds late.
On day 3, it will be 65 seconds late.
...
On day 36, it will be 890 seconds late.
On day 37, it will be 905 seconds late (just over 15 minutes).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>

int main()
{
  int seconds_late = 15;
  int day = 1;
  while (seconds_late < 15 * 60)
  {
    day++;
    seconds_late += 25;
  } 

  std::cout << seconds_late << " seconds late on day " << day;
}

@Repeater, how in the world did you decode statements like:
Next day s1 it will be more late than the previous time 25 seconds.

or
Input number until minutes it will be late

???
The clock on the first day has delayed s seconds, and every other day s1 more than the previous one. Write the program counting in a few days
the clock will be late for 15 minutes. All data is of a healthy type.
Agreed with Repeater (day 37), except 15 + 36*25 is 915 seconds, not 905 ;D
Since all you're doing is incrementing variables, can also use a bodiless for loop (semicolon or empty curly braces next to it)
1
2
3
4
5
6
7
8
#include <iostream>
int main() 
{
    int limit = 15*60;
    int day = 1;
    for (int t=15; t<limit; day++, t+=25);
    std::cout << "day " << day << '\n';
}

day 37
Topic archived. No new replies allowed.