File tree Expand file tree Collapse file tree 1 file changed +30
-4
lines changed Expand file tree Collapse file tree 1 file changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -9,19 +9,45 @@ The equivalent Decimal Number : 485
9
9
10
10
+ 1. Figure out howo to convert octal to decimal
11
11
745 = (7 * 8^2) + (4 * 8^1) + (5 * 8^0) = 485
12
- 1.5 Input
12
+ + 1.5 Input
13
13
2. Pow function
14
14
3. Function to count amount of digits
15
15
4. Write function to iterate over digits and return sum of powers
16
- 5. Invalid input
16
+ + 5. Invalid input
17
17
6. Test
18
18
7. Cpplint test
19
19
8. Add and push
20
20
*/
21
21
22
22
#include <stdio.h>
23
-
23
+
24
+ enum boolean_for_validation {
25
+ TRUE = 1 ,
26
+ FALSE = 0
27
+ };
28
+
29
+ int input_octal (int * octal );
30
+ void print_invalid_input ();
31
+
24
32
int main () {
25
-
33
+ int octal = 0 ;
34
+ if (input_octal (& octal )) {
35
+ printf ("%d" , octal );
36
+ } else {
37
+ print_invalid_input ();
38
+ }
26
39
return 0 ;
27
40
}
41
+
42
+ void print_invalid_input () {
43
+ printf ("n/a" );
44
+ }
45
+
46
+ int input_octal (int * octal ) {
47
+ int is_valid = TRUE;
48
+ char endline = '\0' ;
49
+ if (!scanf ("%d%c" , octal , & endline ) || endline != '\n' ) {
50
+ is_valid = FALSE;
51
+ }
52
+ return is_valid ;
53
+ }
You can’t perform that action at this time.
0 commit comments