I Can't Stop This Loop - Help?

Hello,

Trying to input a and reach b by counting to it with c! But it just keeps looping (frown) need help!

Input --> a = 1, b = 12, c = 1
Output --> 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9, 10, 11, 12

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
using namespace std;
int main()
{
int a;
int b;
int c;
int d;

cout << "Please Give Me A Number & We Will Call It A (Start Time):\n";
cin  >> a;
cout << "Please Give Me A Number & We Will Call It B (End Time):\n";
cin  >> b;
cout << "Please Give Me A Number & We Will Call It C (Interval):\n";
cin  >> c;
d = c + a;
do {c + a, cout << d;}
while ( c + a < b );
return 0;
}
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
#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
using namespace std;
int main()
{
int a;
int b;
int c;

cout << "Please Give Me A Number & We Will Call It A (Start Time):\n";
cin  >> a;
cout << "Please Give Me A Number & We Will Call It B (End Time):\n";
cin  >> b;
cout << "Please Give Me A Number & We Will Call It C (Interval):\n";
cin  >> c;

do
{
    std::cout << a << "\n";//start from a/
    a +=  c;//increment a by interval (c) ...

}while (a <= b);//... until we reach b (or thereabouts) ...
}

edit: you''ll of course need additional checks that b > a, c > 0 , input validation
Last edited on
More words...

do {c + a, cout << d;}
while ( c + a < b );

c+a; is a do-nothing statement. It discards the sum and does nothing, effectively. You surely meant to assign something there which would affect C or A so that the loop would end.

Thanks everyone. I'm out and about. Will report back soon when I do a re-write and compile.
GunnerFunner,
It works perfect - thank you for the distinction of increment over the introduction of a new variable.
I am looking to turn this code into a time creator. IE

Start Time - 08:00:00
End Time - 12:00:00
Increment - 00:15:00

0815
0830
0845
0900
0915

etc -

I am new to the process - I figured I would ask the masters on here. I will keep working on it. Thank you all so very much.
Topic archived. No new replies allowed.