How can I Convert number to another

I am Not Good in c++

When running code, convert 1 to 1 2
2 to 2 3
3 to 3 4
4 to 4 5
5 to 5 6
6 to 6 7
7 to 7 8
8 to 8 9
9 to 9 10
10 to 10 11
11 to 1 3

when running code first row will be 1 2 3 4 5 but I want first row

to be 1 2 - 2 3 - 3 4 - 4 5 - 5 6


second row will be 1 2 3 4 6 but I want it to be

1 2 - 2 3 - 3 4 - 4 5 - 6 7

AND SO ON



#include <iostream>
#include <fstream>
using namespace std;

int main()
{
const int NMAX = 11;
int i = 0;

//Choose ONE of the following
//ofstream out( "output.txt" ); // for file
ostream & out = cout; // for screen

for ( int a = 1; a <= NMAX - 2; a++ )
{
for ( int b = a + 1; b <= NMAX - 1; b++ )
{
for ( int c = b + 1; c <= NMAX; c++ )
{
for ( int d = c + 1; d <= NMAX; d++ )
{
for ( int e = d + 1; e <= NMAX; e++ )
{




int n = 100 * a + 10 * b + c + d + e;
i++;
//out << i << ": " << n << '\n';
out << i << ": " << a << " " << b << " " << c << " " << d << " " << e << '\n';
}
}
}
}
}
}
Last edited on
for(i = 0; i < ?; i++)
cout << i+1 << " " << i+2<<" "; 1 2 2 3 3 4 4 5 .... is this what you seek?


No,

when run,

For example,

First row 1 2 3 4 5 normaly but I want it instead of 1 it write A, instead of 2 it write B

instead of 3 it write C, instead of 4 it write D, instead of 5 it write E

when run I want write A B C D E instead of 1 2 3 4 5 (For first row)


when run I want write A B C D F instead of 1 2 3 4 6 (For second row)




(I mean,
when run put A instead of 1
when run put B instead of 2
when run put C instead of 3
when run put D instead of 4
when run put E instead of 5
when run put F instead of 6
when run put G instead of 7
when run put H instead of 8
when run put I instead of 9
when run put j instead of 10
when run put K instead of 11)

First Row will be A B C D E
Second Row will be A B C D F
Third Row wil be A B C D G

AND SO ON







Last edited on
Your former example is very different from your latter, and that holds true for the corresponding solutions.
However, by and large, you probably need to:
step 1: load the input integers into a container, let’s say a std::vector<int> or a std::queue<int> (or even a C-style array).

Step 2: output the corresponding values from a matching table.

About the last point: it seems that for every number you get, you need to output a letter from the English alphabet. In that case, you don’t need a table of matches.
Just use the ASCII table, where A is 65, B is 66 and so on.

I think you want to work this out by your own, don’t you?
Happy coding!

P.s.
This doesn’t seem that far from what you were struggling with in February:
http://www.cplusplus.com/forum/beginner/249997/
Wouldn’t it be simpler to explain us what are you trying to achieve?

And please, use code tags:
http://www.cplusplus.com/articles/jEywvCM9/
Last edited on
I think I cant explain what I mean

My english is not good, my c++ also


lets forget about above two example

I will try to explain in another way

when run code first row is 1 2 3 4 5
when run code first row is 1 2 3 4 6
when run code first row is 1 2 3 4 7

and so on

when 1 appear on screen it cout "tom" instead of 1
when 2 appear on screen it cout "john" instead of 2
when 3 appear on screen it cout "maria" instead of 3
when 4 appear on screen it cout "scarlet" instead of 4
when 5 appear on screen it cout "antony" instead of 5
when 6 appear on screen it cout "kim" instead of 6
when 7 appear on screen it cout "thomas" instead of 7
when 8 appear on screen it cout "george" instead of 8
when 9 appearon screen it cout "tanita" instead of 9
when 10 appearon screen it cout "victor" instead of 10
when 11 appearon screen it cout "patrick" instead of 11


then

first row,

tom john maria scarlet antony
(1) (2) (3) (4) (5)

second row,

tom john maria scarlet kim
(1) (2) (3) (4) (6)

Third row,

tom john maria scarlet thomas

and so on
@avnitoto
None of the explanations you have given above make any sense at all.
Neither did any of the explanations you gave when you previously posted back in February.

This has nothing to do with your English. It has everything to do with you refusing to state what your original problem was. Forget trying to rephrase it: just state the original problem.
string tbl[] = {"", "tom", "john", "maria", "scarlet"};
for(int x = 1; x < 4; x++)
cout << tbl[x]; //1 is tom, etc.

Thank you jonnin for your reply

I am too weak for c++

I put your code to tenth line, when run it did just first row

but I want to do for all 462 row when running

(perhaps I put your code wrong line)


when run Under code (your code start from line 10)

first code is just ok

(when 1 appear on screen it cout "tom" instead of 1
when 2 appear on screen it cout "john" instead of 2
when 3 appear on screen it cout "maria" instead of 3
when 4 appear on screen it cout "scarlet" instead of 4
when 5 appear on screen it cout "antony" instead of 5
when 6 appear on screen it cout "kim" instead of 6
when 7 appear on screen it cout "thomas" instead of 7
when 8 appear on screen it cout "george" instead of 8
when 9 appearon screen it cout "tanita" instead of 9
when 10 appearon screen it cout "victor" instead of 10
when 11 appearon screen it cout "patrick" instead of 11)


#include <iostream>
#include <fstream>
using namespace std;

int main()
{
const int NMAX = 11;
int i = 0;

string tbl[] = {"", "tom ", "john ", "maria ", "scarlet ", "antony ", "kim" };
for(int x = 1; x < 6; x++)
cout << tbl[x];



//Choose ONE of the following
//ofstream out( "output.txt" ); // for file
ostream & out = cout; // for screen

//1 is tom, etc.

for ( int a = 1; a <= NMAX - 2; a++ )
{
for ( int b = a + 1; b <= NMAX - 1; b++ )
{
for ( int c = b + 1; c <= NMAX; c++ )
{
for ( int d = c + 1; d <= NMAX; d++ )
{
for ( int e = d + 1; e <= NMAX; e++ )
{




int n = 100 * a + 10 * b + c + d + e;
i++;

//out << i << ": " << n << '\n';
out << i << ": " << a << " " << b << " " << c << " " << d << " " << e << '\n';




}
}
}
}
}
}
you just need to load the string table with all the possible names and then iterate your numbers to print them back out.

perhaps its after all the loops, near i++, cout << tbl[n] ? I can't tell, your code does not make a lot of sense.

a table of 500 names is going to be annoying to manage. But from what you have given us about what you really want to do here, I don't see much else .... you could put them in a file, but that is really the same thing as hard coded list.
Last edited on
It seems that a,b,c,d,e have values that are in [1..NMAX], where NMAX is "small".
The number to name lookup table is not huge.

You have it, you use it:
out << i << ": " << tbl[a] << ' ' << tbl[b] << ' ' << tbl[c] << '\n';
Topic archived. No new replies allowed.