Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming

Reply
 
LinkBack Thread Tools
Old 10-15-09   #1 (permalink)
Folding Fanatic
 
tofunater's Avatar
 
intel nvidia

Join Date: Sep 2006
Location: Dekalb, IL
Posts: 2,444

Rep: 200 tofunater is acknowledged by manytofunater is acknowledged by manytofunater is acknowledged by many
Unique Rep: 173
Folding Team Rank: 292
Trader Rating: 24
Default Caesar Cipher in C++

I know you guys are probably getting sick of my programming questions, but you guys are a lot more helpful than my TA has ever been, so here it goes. I need to develop a reverse Caesar cipher (A=D. Z=C, etc) function as part of a larger program. I'm not sure what I've done wrong :

Code:
//Function 1 - undoes the Caesar Cipher
char revCaesar(char ch)
{
     if(isupper(ch))
            
           {
            if(ch <= D and ch >= Z)
                  {
                   int ch;
                   ch = ch - 3;
                   return ch;
                  }
            else
                
                switch(ch)
                            {
                            case 'A':
                            ch = "X";
                            break;
                            case 'B':
                            ch = "Y";
                            break;
                            case 'C':
                            ch = "Z";
                            break;
                            }
            return ch;
           }
     else
           {
            if(ch <= d or ch >= z)
                  {
                   int ch;
                   ch = ch - 3;
                   return ch;
                  }
            else
                  char s;
                  switch(ch)
                            {
                            case 'a':
                            s = "x";
                            break;
                            case 'b':
                            s = "y";
                            break;
                            case 'c':
                            s = "z";
                            break;
                            }
            return ch;
}
}
Any ideas?
__________________

Quote:
Originally Posted by iandh View Post
People like this know deep down inside that they are absolutely worthless, so they must constantly come up with new ways to give themselves worth, otherwise they may be tempted to end it all one day by OD'ing on Care-Bears marathons.

System: Hedonism, Stanford Style
CPU
i7 920 D0
Motherboard
Asus P6T6 WS revolution
Memory
6 gigs G-skill
Graphics Card
Tri-sli 260's
Hard Drive
620aaks
Sound Card
on board
Power Supply
Zalman 850
Case
hardwood techstation(soon)
CPU cooling
GTZ/bix 360/355 (soon)
GPU cooling
water (soon)
OS
Vista 64
Monitor
22" Samsung 225BW
Overclock.net - 2009 Chimp Challenge Champions

Last edited by tofunater : 10-15-09 at 09:33 PM
tofunater is offline I fold for Overclock.net   Reply With Quote
Old 10-15-09   #2 (permalink)
Case Modder
 
Spotswood's Avatar
 
Join Date: Jul 2008
Location: New Hampshire, USA
Posts: 235

Rep: 46 Spotswood is acknowledged by some
Unique Rep: 39
Trader Rating: 0
Default

There are a lot of basic syntax errors in that function, but the most glaring mistake I see is that you should be calling isupper().
__________________
Rich
Custom Wooden Case Builder
Overclock.net Mod of the Month
Spotswood is offline   Reply With Quote
Old 10-15-09   #3 (permalink)
Folding Fanatic
 
tofunater's Avatar
 
intel nvidia

Join Date: Sep 2006
Location: Dekalb, IL
Posts: 2,444

Rep: 200 tofunater is acknowledged by manytofunater is acknowledged by manytofunater is acknowledged by many
Unique Rep: 173
Folding Team Rank: 292
Trader Rating: 24
Default

Quote:
Originally Posted by Spotswood View Post
There are a lot of basic syntax errors in that function, but the most glaring mistake I see is that you should be calling isupper().
Seriously? My assignment notes must be wrong, dammit. Fixed it now. Would you notate the syntax errors for me, I really am lost as to what is wrong.
__________________

Quote:
Originally Posted by iandh View Post
People like this know deep down inside that they are absolutely worthless, so they must constantly come up with new ways to give themselves worth, otherwise they may be tempted to end it all one day by OD'ing on Care-Bears marathons.

System: Hedonism, Stanford Style
CPU
i7 920 D0
Motherboard
Asus P6T6 WS revolution
Memory
6 gigs G-skill
Graphics Card
Tri-sli 260's
Hard Drive
620aaks
Sound Card
on board
Power Supply
Zalman 850
Case
hardwood techstation(soon)
CPU cooling
GTZ/bix 360/355 (soon)
GPU cooling
water (soon)
OS
Vista 64
Monitor
22" Samsung 225BW
Overclock.net - 2009 Chimp Challenge Champions
tofunater is offline I fold for Overclock.net   Reply With Quote
Old 10-15-09   #4 (permalink)
Case Modder
 
Spotswood's Avatar
 
Join Date: Jul 2008
Location: New Hampshire, USA
Posts: 235

Rep: 46 Spotswood is acknowledged by some
Unique Rep: 39
Trader Rating: 0
Default

Quote:
Originally Posted by tofunater View Post
Seriously? My assignment notes must be wrong, dammit. Fixed it now. Would you notate the syntax errors for me, I really am lost as to what is wrong.
Code:
//Function 1 - undoes the Caesar Cipher
char revCaesar(char ch)
{
    if(isupper(ch))

    {
        if(ch <= D and ch >= Z)  // D and Z should be surrounded by single quotes
        {
            int ch;
            ch = ch - 3;
            return ch;
        }
        else

            switch(ch)
        {
            case 'A':
                ch = "X"; // use single quotes
                break;
            case 'B':
                ch = "Y";
                break;
            case 'C':
                ch = "Z";
                break;
        }
        return ch;
    }
    else
    {
        if(ch <= d or ch >= z)
        {
            int ch;
            ch = ch - 3;
            return ch;
        }
        else // missing {
            char s;
        switch(ch)
        {
        case 'a':
            s = "x"; // use single quotes
            break;
        case 'b':
            s = "y";
            break;
        case 'c':
            s = "z";
            break;
        }
        return ch;  // return s, no?
       // missing }
    }
}
__________________
Rich
Custom Wooden Case Builder
Overclock.net Mod of the Month
Spotswood is offline   Reply With Quote
Old 10-15-09   #5 (permalink)
Folding Fanatic
 
tofunater's Avatar
 
intel nvidia

Join Date: Sep 2006
Location: Dekalb, IL
Posts: 2,444

Rep: 200 tofunater is acknowledged by manytofunater is acknowledged by manytofunater is acknowledged by many
Unique Rep: 173
Folding Team Rank: 292
Trader Rating: 24
Default

thanks for that spotswood, and... that did it. Once again, my class notes failed me. The switch statements were modeled exactly off of what I was given
__________________

Quote:
Originally Posted by iandh View Post
People like this know deep down inside that they are absolutely worthless, so they must constantly come up with new ways to give themselves worth, otherwise they may be tempted to end it all one day by OD'ing on Care-Bears marathons.

System: Hedonism, Stanford Style
CPU
i7 920 D0
Motherboard
Asus P6T6 WS revolution
Memory
6 gigs G-skill
Graphics Card
Tri-sli 260's
Hard Drive
620aaks
Sound Card
on board
Power Supply
Zalman 850
Case
hardwood techstation(soon)
CPU cooling
GTZ/bix 360/355 (soon)
GPU cooling
water (soon)
OS
Vista 64
Monitor
22" Samsung 225BW
Overclock.net - 2009 Chimp Challenge Champions
tofunater is offline I fold for Overclock.net   Reply With Quote
Old 4 Weeks Ago   #6 (permalink)
Security Sleuth
 
Pooping^fish's Avatar
 
intel nvidia

Join Date: Jul 2007
Location: egypt
Posts: 1,263

Rep: 67 Pooping^fish is acknowledged by some
Unique Rep: 62
Trader Rating: 3
Default

Why is ch an int? Just use a char and the correct single quotes.
You need to define or quote D / Z.

Code:
if(ch <= d or ch >= z)
        {
            int ch;
            ch = ch - 3;
            return ch;
        }
Its going to use the ch within local scope. Essentially you just did (arb-value or 0) - = 3 it seems.
__________________
Quote:
"O, hai! Want som pRon? Dwnlod ths kodk frst. Its teh bst pRonz ever, we prmis." -GibbyGano
Proud Member of the Linux Gaming Community
I am your friend.

System: ragequit
CPU
Q9550 4ghz @ 1.25v
Motherboard
Asus Max 2 formula
Memory
OCZ LV blade 1:1 950mhz
Graphics Card
8800gtx 610/1ghz
Hard Drive
7200.10 250gb
Sound Card
X-FI Extreme Music
Power Supply
750w Toughpower
Case
Lian li pc-65
CPU cooling
TRUE
GPU cooling
stock
OS
leetlinucks
Monitor
24" Westy
Pooping^fish is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -5. The time now is 09:08 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2009 Shogun Interactive Development. Most rights reserved.
Page generated in 0.12398 seconds with 8 queries