Thread: Programming input question

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    6

    Programming input question

    I had to write a program that read the encrypted message... ":mmZ\dxZmx]Zpgy"
    This was accomplished. The completed program is below, however it is set up now so that a user will input an encrypted message and then the program will decrypt the message. I dont want this. pretty much I want to run the program and have it automatically consider ":mmZ\dxZmx]Zpgy"
    as the message that is already input. How do I do that?

    Code:
    #include<iostream>
    using namespace std;
    int main()
    {
    
    
    char in[100];
    char out[100];
    int key,count;
    
    cout<<"Enter encrypted code: ";
    cin.getline(in,100);
    
      for(key=1;key<=100;key++)
      {
         for(count=0;in[count]!='\0';count++)
         {
              if(in[count]-key<32)
              out[count]=in[count]-key-32+127;
              else
              out[count]=in[count]-key;
          }
           cout<<"Key "<<key<<" Decoded Message: ";
           cout<<out<<endl;
      }
    system("pause");
    return 0;
    }

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Are you completely sure that you understand the code you've given...?..
    If you can write a program to read the input and use it....you should...by definition.. be able to do that without the input...in fact the logical step is to do the former after the later !..
    By the way...
    1.If you are allowed to use strings ..consider using std::string
    2. In <iostream> ... getline is used as
    Code:
    getline(cin,your_string)
    ___
    OR you can just use a
    Code:
    in = ":mmZ\dxZmx]Zpgy";
    for the purpose...though it isn't a good idea..
    Last edited by manasij7479; 05-13-2011 at 01:52 PM.

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    6

    Yes i get it, haha. I am getting an error message.

    The output isnt right this way.
    Code:
    #include<iostream>
    using namespace std;
    int main()
    {
    
    
    char in[100]=":mmZ\dxZmx]Zpgy";
    char out[100];
    int key,count;
    
      for(key=1;key<=100;key++)
      {
         for(count=0;in[count]!='\0';count++)
         {
              if(in[count]-key<32)
              out[count]=in[count]-key-32+127;
              else
              out[count]=in[count]-key;
          }
           cout<<"Key "<<key<<" Decoded Message: ";
           cout<<out<<endl;
      }
    system("pause");
    return 0;
    }.

  4. #4
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    "Yes i get it, haha. I am getting an error message."
    What an error message!!!!.....Compilers must be getting AI-stuffed.....bad for those who spew "meaningful" error messages..

    How about you remove the . after the final brace...and replace the system("pause");
    with
    Code:
    cin.get();
    And the correct output is at Key 88 ..why did you need to print out the 99 wrong outputs ?

  5. #5
    Registered User
    Join Date
    May 2011
    Posts
    6

    no change.

    We get examples of how the program should run from our professor. Our program should function exactly as his does. I know the correct output is at line 88, however it is supposed to print "Attack at dawn!" My program prints "Attak at Dawn" and a Heart symbol at the end. I get an error that says "unknown escape sequence '\d'..."

  6. #6
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Sorry..overlooked that.. :|]
    Change the string to
    ":mmZ\\dxZmx]Zpgy"
    Your professor should have warned you about trying to operate on unintended escape sequences... Putting another \ nullifies that..

  7. #7
    Registered User
    Join Date
    May 2011
    Posts
    6

    Awesome

    Thanks. Yea i took that code from the book. The professor actually did give us...

    Hint: The correct key is 88 and the message is "Attack at dawn!"

    It is easier is you store the encrypted message within your program as:

    char[ ] = ":mmZ\\dxZmx]Zpgy";

    I thought the extra '\' was only a typo. Appreciate the help.

  8. #8
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    took that code from the book
    Do that again and again..and you'd always be stuck in the same place.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Socket programming - input from client problem
    By Kitase in forum C Programming
    Replies: 2
    Last Post: 10-12-2010, 07:53 AM
  2. input validation - new to programming
    By bigzeppelin2k in forum C Programming
    Replies: 2
    Last Post: 10-31-2003, 06:44 PM
  3. Total newb to programming here... Question about the many programming languages. Ty!
    By tsubotakid1 in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 10-05-2003, 10:32 AM
  4. File input for histogram (programming)
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 07-22-2002, 08:26 PM