From: Chris on
Hi group,

I have a quick question that has been confusing me:

I have the following bit of code (int a class):

{
cout << "Please enter n for Caesar encryption: ";
cin >> password;

password = password % 26;

return OK;
}

password is of type int (but i tried it with char and short also). When for
example I enter "1" at the console, password contains after the operation 23
?!?

If I write "password = 1 % 26;" I get the correct solution (1 mod26 == 1).

Can anybody tell my why this is so? I am using the gnu compiler.

Thanks
Chris


From: Chris on

"Chris" <nospam(a)invalid> wrote in message
news:96dab$43cfb971$5438fad1$30243(a)news.usenext.de...

> I have the following bit of code (int a class):
of course i meant "in a class"


From: sathyashrayan on
In article <96dab$43cfb971$5438fad1$30243(a)news.usenext.de>,
nospam(a)invalid says...
> Hi group,
>
> I have a quick question that has been confusing me:
>
> I have the following bit of code (int a class):
>
> {
> cout << "Please enter n for Caesar encryption: ";
> cin >> password;
>
> password = password % 26;
>
> return OK;
> }
>
> password is of type int (but i tried it with char and short also). When for
> example I enter "1" at the console, password contains after the operation 23
> ?!?
>
> If I write "password = 1 % 26;" I get the correct solution (1 mod26 == 1).
>
> Can anybody tell my why this is so? I am using the gnu compiler.
>
> Thanks
> Chris
>
>
>
I am not very good at explaining.

Think of a wood log which is divided into two equal parts. You will not
get anything after you divide it into two equal parts. But what will
happen when it is not divided into two equal parts? You will definitely
get a remaining log.


If you want to consider a *limit* for the wood log ( you don't want the
wood pice to exceed the limit) you put it in the for loop and evaluate
for non zero.

for(log = 10 ; log <= 0 ;var = var % 3)
From: Chris on
Are we talking about the same question here?

"sathyashrayan" <sathyashrayan(a)gmail.com> wrote in message
news:MPG.1e3a1f4ece74e429989680(a)127.0.0.1...
> In article <96dab$43cfb971$5438fad1$30243(a)news.usenext.de>,
> nospam(a)invalid says...
>> Hi group,
>>
>> I have a quick question that has been confusing me:
>>
>> I have the following bit of code (int a class):
>>
>> {
>> cout << "Please enter n for Caesar encryption: ";
>> cin >> password;
>>
>> password = password % 26;
>>
>> return OK;
>> }
>>
>> password is of type int (but i tried it with char and short also). When
>> for
>> example I enter "1" at the console, password contains after the operation
>> 23
>> ?!?
>>
>> If I write "password = 1 % 26;" I get the correct solution (1 mod26 ==
>> 1).
>>
>> Can anybody tell my why this is so? I am using the gnu compiler.
>>
>> Thanks
>> Chris
>>
>>
>>
> I am not very good at explaining.
>
> Think of a wood log which is divided into two equal parts. You will not
> get anything after you divide it into two equal parts. But what will
> happen when it is not divided into two equal parts? You will definitely
> get a remaining log.
>
>
> If you want to consider a *limit* for the wood log ( you don't want the
> wood pice to exceed the limit) you put it in the for loop and evaluate
> for non zero.
>
> for(log = 10 ; log <= 0 ;var = var % 3)


From: Francis Glassborow on
In article <96dab$43cfb971$5438fad1$30243(a)news.usenext.de>, Chris
<nospam(a)invalid.?.invalid> writes
>Hi group,
>
>I have a quick question that has been confusing me:
>
>I have the following bit of code (int a class):
>
>{
>cout << "Please enter n for Caesar encryption: ";
>cin >> password;
>
>password = password % 26;
>
>return OK;
>}
>
>password is of type int (but i tried it with char and short also). When for
>example I enter "1" at the console, password contains after the operation 23
>?!?
>
>If I write "password = 1 % 26;" I get the correct solution (1 mod26 == 1).
>
>Can anybody tell my why this is so? I am using the gnu compiler.
>
>Thanks
>Chris
>
>
Please post a small program that demonstrates the problem as your
description just leaves far too many places where you might be causing
the problem.

--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects
 |  Next  |  Last
Pages: 1 2
Prev: What is panic?
Next: Help me about pointer...