So basically i need to write a code that the user needs to enter either 'e' or 'd'. When 'd' is entered thus the user needs to input as well an array of numbers then outputs the letter that the number represents in "array2[z]"
eg:
[input]68 45 71 82 1 20[/input]
abcdefg
[b]So basically this is my code (the one i was suggested)[/b]
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
usingnamespace std;
#define K 2000
void main(){
char array2[z]={"A gentle, dull flickering flame, burns in the marble hearth.\
Its dim light scarcely illuminates the small, cozy room with its\
The dismal light plays softly causing shadows over the solitary \
figure of a wooden desk at which Allen was roaming through his \
memories. Thinking back in the past where he once had a\
friendship which was out righteously incredible. \
She was the girl of his dreams, in a way which she \
had everything he had ever sought out in a beautiful and clever girl.\
Most of all she had his heart. Her style was incredible in the way\
the outfits she would wear would match perfectly\
giving a deep vibrant lively feeling."};
int S[K], a, Q=0, i;
char e, d;
int z = 0;
cin>>a;
if(a=='d'){
while( z >= 0 && z < 256){
cin >> z;
cout << static_cast<unsignedchar>(z);
}
cin>>z;}}
[b]And this is my original code i made which was kinda stupid and wouldn't work properly[/b]
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
usingnamespace std;
#define N 1000
void main(){
char array1[a]={"A gentle, dull flickering flame, burns in the marble hearth.\
Its dim light scarcely illuminates the small, cozy room with its\
The dismal light plays softly causing shadows over the solitary \
figure of a wooden desk at which Allen was roaming through his \
memories. Thinking back in the past where he once had a\
friendship which was out righteously incredible. \
She was the girl of his dreams, in a way which she \
had everything he had ever sought out in a beautiful and clever girl.\
Most of all she had his heart. Her style was incredible in the way\
the outfits she would wear would match perfectly\
giving a deep vibrant lively feeling."};
int S[N];
int z;
int i, a, Q=0;
char e;
char d;
cin>>z;
while(z=='d'){
cin>>S[i];
for(i=0;i<=array1[a];i++)
cin>>S[a];
cout << a<<endl;
for(i=0;i<array1[a];i++)
cout << a<<endl;
}}
[b]Any suggestions and help on fixing my code to work??[/b] Remember: I need to use the d as an input. Then input an array of numbers to output the characters corresponding in the first array.
So, it would appear you are gathering values and should be using those values to index the string stored in array1. There is a problem, however, if that's what you're intended to do.
This:
[input]68 45 71 82 1 20[/input]
abcdefg
Does not correspond to the string stored in array1. A casual inspection of the string reveals that the character stored at position one is a space or possibly an 'A' depending on whether the user input interprets 0 or 1 as the first element, but it is definitely not an 'f'.