-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject.cpp
52 lines (45 loc) · 1.06 KB
/
project.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// CpE 3110 FS23 Honors Project
// File: project.cpp
// Author: Nathan Mejia
#include <iostream>
#include <string>
#include <bitset>
#include <sstream>
#include "ibmFloat.h"
int main()
{
IBMFloat num1, num2;
bool subtraction;
std::string input;
std::stringstream native_flt;
do
{
std::cin >> input;
num1 = IBMFloat(input);
std::cin >> input;
if (input == "+")
subtraction = 0;
else if (input == "-")
subtraction = 1;
else
break;
std::cin >> input;
num2 = IBMFloat(input);
if (subtraction)
{
std::cout<<num1<<" - "<<num2<<" = "<<(num1-num2)<<"\n";
native_flt<<num1.toNativeFloat()<<" - "
<<num2.toNativeFloat()<<" = "
<<(num1-num2).toNativeFloat()<<"\n";
}
else
{
std::cout<<num1<<" + "<<num2<<" = "<<(num1+num2)<<"\n";
native_flt<<num1.toNativeFloat()<<" + "
<<num2.toNativeFloat()<<" = "
<<(num1+num2).toNativeFloat()<<"\n";
}
} while (!std::cin.eof());
std::cout << native_flt.str();
return 0;
}