Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help All

2 views
Skip to first unread message

Alexander

unread,
Apr 29, 2004, 7:41:58 PM4/29/04
to
Ya ne nahoju oshibku, pomogite!!!!


#include <iostream.h>
#include <string.h>

long reverse(long num);
char decoding(char c, long n);
int strpos(char s, char *t);


long num, rev_num=0, temp_num=0;
char message[80];
char decoded[80];

void main()
{


cout << "Please enter the positive number: ";
cin >> num;

cout << "Please enter the message for decoding: ";
int i=0;
message[i]=cin.get();
while(message[i++] != '.') //get the message, while '.' character
{
message[i]=cin.get(); //cin first caracter
//take caracter to decoding
}
decoded[i]=decoding(message[i], reverse(num));
cout << decoded; //print decoded message
}

//string position function

int strpos(char s, char *t)
{
int i;
for (i = 0; i!='\0'; i++)
{
if (s == t[i])
{
break;
}
}
return i;
}

//The reverse number function

long reverse(long num)

{
long i = 10;

if (num < 10)
return num;
else
{
for(i; num%i != num; i *= 10);
return ((num%10) * i/10) + reverse(num/10);
}
}

//Decoding function

char decoding(char c, long n)
{
long temp_num;
temp_num=n;
char alpha[]={"abcdefghijklmnopqrstuvwxyz"};
char d;
int i=0;
while(c!='.')
{
if(num==0)
num=temp_num;
if(c!=' ')
{
i=strpos(c, alpha);
d=alpha[i + n%10];
n=n/10;
}
else
{
d=c;

}
}
return d;
}

0 new messages