Hi, we have this school activity that is rush for tonight. I would really appreciate if somebody will help me. It would really mean a lot to me. So here is the problem that were tasked to us to create a C++ program.

Problem: Write a C++ program to perform addition of two hexadecimal numerals each with up to 10 digits. If the result of the addition is more than 10 digits long, then simply give the output message “*********Overflow Error *********** ” and not the results in addition. Use arrays to store hexadecimal numerals as arrays of characters. Include a loop to repeat this calculation for new numbers until the user says he or she wants to end the program. Also, provide data validation on all inputs. See sample output.

Sample output:

Enter a hexadecimal number of 10 or fewer hex digits
Hex digits are 0-9 A-F Code requires uppercase A through F
Press lower case q to stop entry of the hex digits
DEDCBA9876

Enter a hexadecimal number of 10 or fewer hex digits
Hex digits are 0-9 A-F Code requires uppercase A through F
Press lower case q to stop entry of the hex digits
123456789A

DEDCBA9876
+ 123456789A
----------------------
F111111110
y continues
Enter a hexadecimal number of 10 or fewer hex digits
Hex digits are 0-9 A-F Code requires uppercase A through F
Press lower case q to stop entry of the hex digits
FEDCBA9876

Enter a hexadecimal number of 10 or fewer hex digits
Hex digits are 0-9 A-F Code requires uppercase A through F
Press lower case q to stop entry of the hex digits
123456789A

*********Overflow Error ***********

FEDCBA9876
+123456789A
-------------------
1111111110
n exits

--------------------------------------------------------------------------------------

As of now here is my code, it was actually one-fourth of the whole problem i guess and i'm really stucked so i really need help.

Code:

``````#include <iostream>
#include <string>
using namespace std;

void part1 ();
void part2 ();
char lowercase;
char number1[10]={'0','0','0','0','0','0','0','0','0','0'};
char number2[10]={'0','0','0','0','0','0','0','0','0','0'};
char sum[10]={'0','0','0','0','0','0','0','0','0','0'};

void main ()
{
part1 ();

part2 ();
}

void part1 ()
{
char lowercase1;
partone:

cout<<"********************************************************************"<<endl;
cout<<"Hexadecimal digits are the 0-9 A-F Code requires A through F"<<endl;
cout<<"********************************************************************"<<endl;

cin>>number1;

cout<<"To stop the entry of the hex digits, please press lowercase q."<<endl;

cin>>lowercase1;

switch (lowercase1)
{
case 'q':
part2 ();

default:
goto partone;
}
}

void part2 ()
{
char lowercase2;
parttwo:
cout<<"********************************************************************"<<endl;
cout<<"Hexadecimal digits are the 0-9 A-F Code requires A through F"<<endl;
cout<<"********************************************************************"<<endl;

cin>>number2;

cout<<"To stop the entry of the hex digits, please press lowercase q."<<endl;

cin>>lowercase2;

switch (lowercase2)
{
case 'q':
exit (1);

default:
part2 ();
}

void mathematics ()
{
cout<<"		"<<number1<<endl;
cout<<"+	"<<number2<<endl;
cout<<"--------------------------"<<endl;
cout<<"		"<<sum<<endl;
}``````

-------------------------------------------------------------------

Thats what I got so far and theres no particular error. I just dont know how to proceed and i dont know yet the right logic to use. We were to use arrays and functions. Please help me. I really need your help guys. Thank you and Godbless.

Do not use goto and functions like part2, mathematics is never called and you have repeated same lines instead of using a function (refactor to function).

if i wont use goto whats the alternative for that? how will i call mathematics in my program. so far when i simulate it without including the mathematics function, it allows the user to enter the first and second number, then my problem is the logic behind that. How? :(

if i wont use goto whats the alternative for that? how will i call mathematics in my program. so far when i simulate it without including the mathematics function, it allows the user to enter the first and second number, then my problem is the logic behind that. How? :(

1) Call the function input the 2 numbers. Return.
2) Call the function to add the two numbers. Return.
3) Call function to display the answer. Return.
Put all that in a loop that asks if you want to do it again.

For #1, just ask for the 2 numbers, don't try looping in the function. Or input 1 number and call the function a second time for the second number.

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.