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<<"Please enter a hexadecimal number of 10 or fewer hexadecimal digits"<<endl;
cout<<"Hexadecimal digits are the 0-9 A-F Code requires A through F"<<endl;
cout<<"********************************************************************"<<endl;
cout<<"Enter your first number:"<<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<<"Please enter a hexadecimal number of 10 or fewer hexadecimal digits"<<endl;
cout<<"Hexadecimal digits are the 0-9 A-F Code requires A through F"<<endl;
cout<<"********************************************************************"<<endl;
cout<<"Enter your second number:"<<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.