Imagine a number system based on the entire English alphabet, that is, using the symbols "0ABCDEFGHIJKLMNOPQRSTUVWXYZ".

Write a program that will calculate the sum of two numbers expressed in this system.

The program should ask for the two numbers and output the numbers and their sum as follows (italics indicate user entered data):

Enter the first number: ABCDE
Enter the second number: WXYZ

ABCDE
WXYZ +
---------
AZACD

- i knew that a character array should be used in this one, but a have no idea how to start, i am hoping that you guys can help me with this, thanks in advance.

## All 8 Replies

Well you can use a character Array Of 27.

And then assign an alphabet to each of them. And then you can get input from the user and write a find function for finding letter.

After you can find the letter store it in one place.
===========
Take the first string. take the last letter.
Take the second string and take the last letter.

then try to match them both and add. Then If the number is greater than 9 You will need to divide the number by ten and then take the absolute value that you will be getting from there. and add that value to the next digit's value .

Well first you determine what your symbols represent. In your system it seems that A = 1 ... Z = 27
So you're talking about a base 28 system.

Therefore a string like "ABCD" will mean A * 28^3 + ... + D * 28^0

My guess would be that the best idea is to do any operations in decimal and then convert back to your alphabet base.
You will want functions that can parse a string for each char and carry out the above arithmetic.

Maybe start by creating a class interface along these lines, and writing the functions one at a time...

``````class CAlphabecimal
{
CAlphabecimal (int);
CAlphabecimal(string);
string InThisBase();
int InDecimal();
CAlphabecimal operator+ (const CAlphabecimal& rhs);
CAlphabecimal& operator= (const CAlphabecimal& rhs);
}``````

Looks like you're going to make GOOD friends with--

--ASCI
--Subtraction

--because you can easily allow someone to enter a phrase and immediately convert the char value into uppercase.

After you convert the char value to uppercase, think about the value of the char in ASCI code then do subtraction. For example--

A = 65 in ASCI so to convert to your code from ASCI to number you'd need to do something like--

int someNumber = ((int)(someChar) - 64);

Now your character will have a number representation.

From there, your new best friends will be--

--int division
--modulus

--because the division will allow you to find out how much you need to carry to the next number to be evaluated, while modulus will determine the remainder value for an answer slot.

I'm assuming your modulus should be %27 because 0 counts as 0 and Z counts as 26. You never encounter the 27th indice because it doesn't exist! So whenever two "char-numbers" add and are over 27, you will need to do int division to determine the carry-value then modulus to determine the remainder-answer for that value.

This is pretty much iteration from the end of the char-array to the beginning. You'll also want to use "dummy-numbers" of 0's appended to the 2nd or first argument secretly so that you can continue to do char-addition without issue.

Im not sure why, but I had a go at making this and succeeded but im not going to give you the solution to it, so you can at least have a go at it yourself. But I will tell you how I managed it.

1. I made two function, one that converts the base 26 number into a base 10 decimal number, and one that converts a base 10 number into a base 26 number.
2. I Used the first function to get the decimal value of the two numbers, and then added them togeather using the data type `unsigned __int64` .
3. Finally I converted the base 10 answer into a base 26 integer.

This worked for me but may not work with extremely large numbers
(numbers larger than unsigned __int64).
But there are many different ways to manage this, so this is only one solution and probably not the best.

Hope this helps.

can ask for the code just please im dying seek making this one my mind is hurting please if its possible begging and kneeling please please a lot

If I showed you my code you would almost certainly not understand it if you are not able to even make a start on it. My advice is, break it up into smaller sections, and do one thing at a time. If you decide to do it the way I suggested you could start with the following things:

- Make a function to convert the base 26 value into a base 10 value with a data type of unsigned __int64, the prototypes should look something like this `unsigned __int64 fromBase26(char *val)` - Make a function to convert the value to base 26 with the prototype similar to this `void toBase26(char *lpTarget, unsigned __int64 val)` With those two functions the problem becomes simple, just simply convert the two base 26 numbers to base 10 (unsigned __int64) values. Then you make a third variable defined as `unsigned __int64 answer = num1 + num2` and then convert is back to base 26 and display it.

Why is it base 26?

Good point, I was just saying base 26 because theres 26 letters in the alphabet, when I did this I just passed the length of the string containing the alphabet values so I wasn't aware what base it actually was. Thanks for the correction :)

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.