sting counting ?how?

Im trying to teach myself string but i cant get anything to display.

how to you take a string and display this kind of list.
I want it to look something like this

One plus one is Two
Two plus one is Three
Three plus one is Four
and so on.....

ive been able to get one row but not one that will continue down. please help

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
34
35
36
37
38
39
#include <iostream>
#include <string>
using namespace std;

string generateCount(string list[], int num)
{
   string output;
   for(int i = 0; i > num; i++)
   {
      output[i] = list[9];
      cout << output[i] << endl;
   }
   cout << "plus one is ";
   cout << output[i +1] << endl;

   return output;
}

int main()
{
   string list[9] =
   {
      "One",
      "Two",
      "Three",
      "Four",
      "Five",
      "Six",
      "Seven",
      "Eight",
      "Nine"
   };

   string count = generateCount(list, 9);

   cout << count;

   return 0;
}


Hi, in short here is my version of your program:
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
#include <iostream>
#include <string>
using namespace std;

void generateCount(string list[], int num)
{
   for(int i = 1; i < num; i++) {
   	cout << list[i-1] << " plus one is " << list[i] << endl;
   }
}

int main()
{
   string list[] = {
      "One",
      "Two",
      "Three",
      "Four",
      "Five",
      "Six",
      "Seven",
      "Eight",
      "Nine"
   };
   const int upToNumber = 9;

   generateCount(list, upToNumber);

   return 0;
}


I think you've misunderstood usage capabilities of loops. You should start with simpler use cases to learn handling the various loop types.
Hey thank you for your help...I can take this and learn from it.
Topic archived. No new replies allowed.