This repository was archived by the owner on Jul 29, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +50
-3
lines changed Expand file tree Collapse file tree 2 files changed +50
-3
lines changed Original file line number Diff line number Diff line change 1
1
#include < iostream>
2
+ #include < fstream>
2
3
#include < string>
3
4
#include " ./add.h"
4
5
5
6
using namespace std ;
6
7
7
- int main (string numbers)
8
- {
9
- return add (" 0" );
8
+ int main () {
9
+ // Display menu options
10
+ cout << " Choose an option:" << endl;
11
+ cout << " 1. Enter the string manually" << endl;
12
+ cout << " 2. Load the string from the input.txt file" << endl;
13
+
14
+ // Get user choice
15
+ int choice;
16
+ cin >> choice;
17
+
18
+ // Variable to store input string
19
+ string inputString;
20
+
21
+ // Handle user choice
22
+ if (choice == 1 ) {
23
+ // Manually enter the string
24
+ cout << " Enter the string: " ;
25
+ cin >> inputString;
26
+ }
27
+ else if (choice == 2 ) {
28
+ // Load the string from the input.txt file
29
+ ifstream inputFile (" input.txt" );
30
+
31
+ // Check if the file is open
32
+ if (!inputFile.is_open ()) {
33
+ cerr << " Error opening the input.txt file." << endl;
34
+ return 1 ;
35
+ }
36
+
37
+ // Read the string from the file
38
+ getline (inputFile, inputString);
39
+ }
40
+ else {
41
+ // Invalid choice, exit with an error message
42
+ cerr << " Invalid choice. Exiting." << endl;
43
+ return 1 ;
44
+ }
45
+
46
+ try {
47
+ // Call the add function and display the result
48
+ cout << " Result: " << add (inputString) << endl;
49
+ }
50
+ catch (const exception& e) {
51
+ // Handle exceptions and display error message
52
+ cerr << " Error: " << e.what () << endl;
53
+ return 1 ;
54
+ }
55
+
56
+ return 0 ;
10
57
}
You can’t perform that action at this time.
0 commit comments