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
#include <iostream>
#include <string>
using namespace std;

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

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

   cout << count;

   return 0;
}
for(int i = 0; i > num; i++)

theres your problem ;)

for (initialization; condition; increase) statement;

and its main function is to repeat statement while condition remains true, like the while loop. But in addition, the for loop provides specific locations to contain an initialization statement and an increase statement. So this loop is specially designed to perform a repetitive action with a counter which is initialized and increased on each iteration.

It works in the following way:

initialization is executed. Generally it is an initial value setting for a counter variable. This is executed only once.
condition is checked. If it is true the loop continues, otherwise the loop ends and statement is skipped (not executed).
statement is executed. As usual, it can be either a single statement or a block enclosed in braces { }.
finally, whatever is specified in the increase field is executed and the loop gets back to step 2.
Change the '>' in line 8 to the sign '<'
Line 13 should be inside the loop, but it still doesnt do what you want.

ensure that output is initialized to no string:
string output = "";

When line 13 is inside the loop, it can look something like this
output += list[i - 1] + " plus one is " + list[i];

It will need some formatting, periods and double spaces. I believe a string can hold the new line character too.
Last edited on
Topic archived. No new replies allowed.