Archived

This topic is now archived and is closed to further replies.

Penguinzchaseme

code problem

Recommended Posts

This code multiplies the number of each letter in a string(a=1 z=26) and checks to see if the modulus of each string divided by 47 is equal. #include <iostream> using namespace std; int main() { char alpha[27]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char UFO[7], Group[7]; int n, x, y, z, a, b=1, c=1; cin>>UFO[7]; cin>>Group[7]; for(n=0; alpha[n];n++); { for(x=0;UFO[x];x++){ if(UFO[x]=alpha[n])UFO[x]=n+1; } for(y=0;Group[y];y++) if(Group[y]=alpha[n])Group[y]=n+1; } for(z=0;UFO[z];z++){ b=b*UFO[z]; } for(a=0;GroupLink

Share this post


Link to post
Share on other sites
I''m not quite sure what your question is but if you expect
cin >> UFO[7];
to fill in 7 characters into the array it wont work, it will actually write into memory that isnt even in the array because UFO[7] points to memory that is 1 memory address past the end of the area. If you want a string you probably want to do
char * UFO;
cin >> UFO;

Share this post


Link to post
Share on other sites