![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Feb 2005
Posts: 4
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Do you have to use that key? Using ASCII would make your app so much easier to code.
|
|
|
|
|
|
#3 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
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];
}
__________________
"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." - Dwight D. Eisenhower |
|
|
|
|
|
#4 | |
|
Newbie
Join Date: Feb 2005
Posts: 4
Rep Power: 0
![]() |
Quote:
|
|
|
|
|
|
|
#5 |
|
Hobbyist Programmer
|
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 |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Feb 2005
Posts: 4
Rep Power: 0
![]() |
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]
} |
|
|
|
|
|
#7 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
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
__________________
"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." - Dwight D. Eisenhower |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Feb 2005
Posts: 2
Rep Power: 0
![]() |
did u know data types.Their is a way ,u should assigned the characters in unsigned character for '-1' ok
|
|
|
|
|
|
#9 |
|
Newbie
Join Date: Feb 2005
Posts: 4
Rep Power: 0
![]() |
how do i make an integer input terminate after "-1" is found
![]() |
|
|
|
|
|
#10 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
You seem to be doing it alright in the code above.
__________________
"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." - Dwight D. Eisenhower |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|