This repository was archived by the owner on Jan 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.cpp
More file actions
124 lines (99 loc) · 1.92 KB
/
Copy pathclient.cpp
File metadata and controls
124 lines (99 loc) · 1.92 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* Christopher Bennett
* Client Side
*/
#include <ctime>
#include <iostream>
#include <string>
#include <boost/asio.hpp>
#include <unistd.h>
using namespace std;
using boost::asio::ip::tcp;
#define addCode 1;
#define subCode 2;
#define divCode 3;
#define multCode 4;
#define notValid 5;
int takeOp(int op)
{
op = toupper(op);
switch (op)
{
case 'A':
return addCode;
break;
case 'S':
return subCode;
break;
case 'D':
return divCode;
break;
case 'M':
return multCode;
break;
default:
return notValid;
break;
}
}
int takeNums()
{
tcp::iostream stream;
string one, two;
float num1, num2;
stream >> one;
cout << "Hello" << "\n";
cout << one << "\n";
if (one == "one"){
cout << "Enter First Number: " << "\n";
cin >> num1;
stream << num1 << endl;
}
return 0;
}
int main(int argc, char* argv[])
{
int code = 0;
string firstNumRequest, secNumRequest, iterationRequest;
char op;
try
{
tcp::iostream stream("localhost", "5678");
if (!stream){
cout << "unable to connect: " << stream.error().message() << "\n";
return EXIT_FAILURE;
}
while (true)
{
cout << "What operation do you want to preform?(a/s/d/m)" << "\n";
cin >> op;
code = takeOp(op);
stream << code << endl;
float num1, num2, ans;
int goAgain;
stream >> firstNumRequest;
if (firstNumRequest == "one"){
cout << firstNumRequest << " first num \n";
cin >> num1;
stream << num1 << endl;
}
stream >> secNumRequest;
if (secNumRequest == "two"){
cout << secNumRequest <<" Second num \n";
cin >> num2;
stream << num2 << endl;
stream << "ans" << endl;
stream >> ans;
}
cout << "Sever says:\t\t" << ans << "\n";
cout << "Do you want to do more caluclations?(0/1)" <<"\n";
cin >> goAgain;
if (goAgain != 0) exit(0);
if(!stream) break;
}
}
catch (exception& e)
{
cout << "Error" << "\n";
}
}