Need to write a simple declaration program w/c apply the substitution method.

substitution table is:
*-a
$-e
/-i
+-o
--u

sample outputs ENCRYPTED MESSAGE:
m$$t m$ *t 9:00*m /n th$ p*rk

DECRYPTED MESSAGE should be: meet me at 9:00am in the park

MY PROGRAM:

#include<stdio.h>
main()
{
  char c;
  clrscr();
  printf("\n Encrypted Message:");
  scanf("%c",&c);
  printf("\n Decrypted Message:");
  if(c=='*')
    printf("a");
  else if(c=='$')
    printf("e");
  else if(c=='/')
    printf("i");
  else if(c=='+')
    printf("o");
  else if(c=='-')
    printf("u");
  else
    printf("Code Error");
  getch();
}

all i get is the Code error message...

tnx,
Claire

Recommended Answers

All 11 Replies

You're not handling the default cause of a non-code. Since the first letter is 'm', and there's no substitution for 'm', your output is correct.

substitution table is:
*-a
$-e
/-i
+-o
--u

Show me where 'm' is in that table.

m$$t m$ *t 9:00*m /n th$ p*rk

Show me where 'm' is in the string.

if(c=='*')
    printf("a");
  else if(c=='$')
    printf("e");
  else if(c=='/')
    printf("i");
  else if(c=='+')
    printf("o");
  else if(c=='-')
    printf("u");
  else
    printf("Code Error");

Now show me where 'm' is handled in this chain of if statements. If you show me all of the correct answers, you'll discover that 'm' is handled in the else clause, which prints "Code Error".

Only vowels have specific encryptions, should i be using %s instead?
The consonants on the other hand should appear as is.

>The consonants on the other hand should appear as is.
Then why are you printing "Code Error" for them? I'm having a hard time understanding why you can't grasp what the problem is even after I've pointed it out twice.

Seriously, just change printf("Code Error"); to putchar(c); . This will correctly handle the first character. You need a loop to handle all of them.

Is a loop possible for characters? I don't know how to do that.

editted program:

#include<stdio.h>
main()
{
  char c[5];
  int i;
  clrscr();
  printf("\n Encrypted Message:");
  for(i=0;i<5;i++){
  scanf("%c",&c[i]);
  }
  c[i]=i;
  printf("\n Decrypted Message:");
  for(i=0;i<5;i++){
  if("c=='*'")
    printf("a");
  else if("c=='$'")
    printf("e");
  else if("c=='/'")
    printf("i");
  else if("c=='+'")
    printf("o");
  else if("c=='-'")
    printf("u");
  else
    putchar(c[i]);
  }
  getch();
}

-output is always aaaa


suggestions pls.

You turned the conditions into string literals. Why? That's clearly not going to do what you intended anymore.

I don't know how to loop characters. I'm hopeless, I'm only doing self-study since our beloved professor don't give a shocks to teach us.

I can forgive ignorance. We were all ignorant at one point. What I tend to be less tolerant of is a complete failure to learn. From all of your questions so far, I get the impression that you haven't learned jack and you're not really trying.

I'm honestly not interested in wasting my help on people who won't learn.

I was able to run the program now. Tnx!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.