Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 2nd, 2005, 10:49 AM   #1
AA225
Newbie
 
Join Date: Feb 2005
Posts: 4
Rep Power: 0 AA225 is on a distinguished road
Question need help making a decoder newbie

hi all,

im trying to make a program that asks the user to input a series of numbers that correspond to various letters and symbols so that a words can be formed. I know how to prompt the user to enter the series of numbers but im stuck on two things:


after the user finishes entering the numbers i want "-1" to be the character to terminate the chain

i.e.

89 57 46 52 -1 <-end of message

and also how do i assign the number to letter and symbols?
i made a notepad file with all the assocation so would i just copy and paste it?

this is the key i have:

------------------------------
code char
2 = 0
16 = 1
31 = 2
92 = 3
55 = 4
67 = 5
42 = 6
1 = 7
97 = 8
32 = 9
48 = -
53 = (space=' ')
98 = !
89 = ,
79 = .
19 = ?
---------------
thats just some of it

i have just started learning c++ so i dont know all the advanced techniques to make this easier :o

as of now all i know is cout, cin, random values, while loop, if-else, do-while, and a bit about creating custom functions and would prefer to stick to this

any examples to help me get going would be greatly appreciated.
AA225 is offline   Reply With Quote
Old Feb 2nd, 2005, 2:01 PM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Do you have to use that key? Using ASCII would make your app so much easier to code.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Feb 2nd, 2005, 3:33 PM   #3
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
First of all, I'm assuming that you're using some sort of loop to input your numbers. You could check for -1, and break the loop when a -1 is found.

For assigning a letter or symbol to a number, I would probably use a function that returns a char variable. You could use a bunch of if statements, or an array as such:

char symbol(int num)
{
     char sets[MAX];
     sets[2] = '0';
     sets[16]='1';
     /* and so on as you need*/

     return sets[num];
}
__________________
&quot;Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children.&quot; - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Feb 2nd, 2005, 3:48 PM   #4
AA225
Newbie
 
Join Date: Feb 2005
Posts: 4
Rep Power: 0 AA225 is on a distinguished road
Quote:
Originally Posted by Mjordan2nd
First of all, I'm assuming that you're using some sort of loop to input your numbers. You could check for -1, and break the loop when a -1 is found.

For assigning a letter or symbol to a number, I would probably use a function that returns a char variable. You could use a bunch of if statements, or an array as such:

char symbol(int num)
{
     char sets[MAX];
     sets[2] = '0';
     sets[16]='1';
     /* and so on as you need*/

     return sets[num];
}
i was hoping to have all the numbers be input at once is that possible with the method you told me
AA225 is offline   Reply With Quote
Old Feb 2nd, 2005, 4:19 PM   #5
Broax
Hobbyist Programmer
 
Broax's Avatar
 
Join Date: Jan 2005
Location: Porto, Portugal
Posts: 142
Rep Power: 4 Broax is on a distinguished road
Send a message via MSN to Broax
Shouldn't something like this:
#include <iostream>
using namespace std;

int main()
{
    int a;
    cin >> a;
    if (a==1);
    cout << 2;
    
    return 0;
    
}

Do the trick?
__________________
PORTUGALPORTUGA
PORTUGALPORTUGA
PORTUGALPORTUGA
PORTUGALPORTUGA
PORTUGALPORTUGA
Broax is offline   Reply With Quote
Old Feb 2nd, 2005, 5:32 PM   #6
AA225
Newbie
 
Join Date: Feb 2005
Posts: 4
Rep Power: 0 AA225 is on a distinguished road
Unhappy

im trying to get all the numbers to be input at once which is fine but what do i put to make read "-1" as a stopping point not another input

#include <iostream>
using namespace std;
char symbol(int number) //function declaration
int main()
{
int number;
char symbol, coded_message;

while (number!=-1)
{
cout<<"Enter your numbers: "<<endl;
cin>>number;
}
coded_message=char symbol(int number); //is this a correct function call?

cout<<coded_message;


//Im having a hard time getting the function definiton right
char symbol(int number) //function heading
{
char sets[2];
     sets[2] = '0';
     sets[16]='1';
/*just testing with two number to letter assignments*/
     return sets[number]
}
AA225 is offline   Reply With Quote
Old Feb 2nd, 2005, 5:39 PM   #7
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
I haven't compiled it, but there are a couple of things that I've noticed off the bat that are wrong with the program.

First of all, the function call is incorrect, and even if you had called it correctly, it would probably not do what you wanted it to. Firstly, the function call should look something like this:

coded_message = symbol(number);

Check out the following link for more information about functions: http://programmingforums.org/forum/showthread.php?t=83

Also, you need to declare the array large enough to hold each and every element. That array would need at least 17 different elements to be able to return sets[16].

For more information on arrays I suggest checking out: http://programmingforums.org/forum/s...ead.php?t=1644
__________________
&quot;Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children.&quot; - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Feb 3rd, 2005, 7:02 AM   #8
suriyaa
Newbie
 
Join Date: Feb 2005
Posts: 2
Rep Power: 0 suriyaa is on a distinguished road
did u know data types.Their is a way ,u should assigned the characters in unsigned character for '-1' ok
suriyaa is offline   Reply With Quote
Old Feb 3rd, 2005, 5:30 PM   #9
AA225
Newbie
 
Join Date: Feb 2005
Posts: 4
Rep Power: 0 AA225 is on a distinguished road
how do i make an integer input terminate after "-1" is found
AA225 is offline   Reply With Quote
Old Feb 3rd, 2005, 5:38 PM   #10
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
You seem to be doing it alright in the code above.
__________________
&quot;Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children.&quot; - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:20 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC