Не вызывается функция
12.02.2015, 22:03. Показов 5072. Ответов 3
Когда код функции находился в главной функции, то выполнялся без нареканий(не считая выскакивания из цикла, если превысить длину входящий строки), когда попытался перенести его в функцию void ex8, то программа словно пропускает функцию.
Пишу в Embarcadero RAD Studio XE.
Код нынешний:
Кликните здесь для просмотра всего текста
C++ | 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
| #include <vcl.h>
#pragma hdrstop
#include <tchar.h>
#include <iostream>
#include <string.h>
#pragma argsused
using namespace std;
void ex8()
{
const int n = 5;
char input[n];
bool next=false;
while (cin.getline(input, n))
{
if (strncmp(input,"stop",4)==0 ||
strncmp(input,"exit",4)==0 ||
strncmp(input,"стоп",4)==0 ) break;
for (int i=0; i < strlen(input); i++)
{
if (!isdigit(input[i]))
{
next=true;
cout << "Вводите только цифры или \"стоп\"/\"stop\"/\"exit\" для перехода к следующей задаче." << endl;
break;
}
}
if (next==true) next=false;
else
{
cout << "Приступаю к преобразованию числа " << input << endl;
int intput=atoi(input);
char output[20]="";
if (intput>999) //1000-3999
{
int i4=(intput / 1000);
cout << "Число тысяч: " << i4 << endl;
while (i4>0)
{
i4-=1;
strcat(output, "M");
}
cout << "Output: " << output << endl;
}
if (intput>99) //100-999
{
int i3=(intput / 100 % 10);
cout << "Число сотен: " << i3 << endl;
if (i3==9)
{
strcat(output, "CM");
}
else
if (i3>=5)
{
i3-=5;
strcat(output, "D");
while (i3>0)
{
i3-=1;
strcat(output, "C");
}
}
else
if (i3==4)
{
strcat(output, "CD");
}
else
while (i3>0)
{
i3-=1;
strcat(output, "C");
}
cout << "Output: " << output << endl;
}
if (intput>9) //10-99
{
int i2=(intput / 10 % 10);
cout << "Число десятков: " << i2 << endl;
if (i2==9)
{
strcat(output, "XC");
}
else
if (i2>=5)
{
i2-=5;
strcat(output, "L");
while (i2>0)
{
i2-=1;
strcat(output, "X");
}
}
else
if (i2==4)
{
strcat(output, "XL");
}
else
while (i2>0)
{
i2-=1;
strcat(output, "X");
}
cout << "Output: " << output << endl;
}
if (intput>0) //1-9
{
int i1=(intput % 10);
cout << "Число единиц: " << i1 << endl;
if (i1==9)
{
strcat(output, "IX");
}
else
if (i1>=5)
{
i1-=5;
strcat(output, "V");
while (i1>0)
{
i1-=1;
strcat(output, "I");
}
}
else
if (i1==4)
{
strcat(output, "IV");
}
else
while (i1>0)
{
i1-=1;
strcat(output, "I");
}
cout << "Output: " << output << endl;
}
if (intput==0) cout << "Ноль? Он обозначается так: —" << endl;
cout << endl << "Римская запись числа " << input << ": " << output << "." << endl;
}
}
}
void _tmain(int argc, _TCHAR* argv[])
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
ex8;
system("pause");
} |
|
Код рабочей программы:
Кликните здесь для просмотра всего текста
C++ | 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
| #include <vcl.h>
#pragma hdrstop
#include <tchar.h>
#include <iostream>
#include <string.h>
#pragma argsused
using namespace std;
void _tmain(int argc, _TCHAR* argv[])
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
const int n = 5;
char input[n];
bool next=false;
while (cin.getline(input, n))
{
if (strncmp(input,"stop",4)==0 ||
strncmp(input,"exit",4)==0 ||
strncmp(input,"стоп",4)==0 ) break;
for (int i=0; i < strlen(input); i++)
{
if (!isdigit(input[i]))
{
next=true;
cout << "Вводите только цифры или \"стоп\"/\"stop\"/\"exit\" для перехода к следующей задаче." << endl;
break;
}
}
if (next==true) next=false;
else
{
cout << "Приступаю к преобразованию числа " << input << endl;
int intput=atoi(input);
char output[20]="";
if (intput>999) //1000-3999
{
int i4=(intput / 1000);
cout << "Число тысяч: " << i4 << endl;
while (i4>0)
{
i4-=1;
strcat(output, "M");
}
cout << "Output: " << output << endl;
}
if (intput>99) //100-999
{
int i3=(intput / 100 % 10);
cout << "Число сотен: " << i3 << endl;
if (i3==9)
{
strcat(output, "CM");
}
else
if (i3>=5)
{
i3-=5;
strcat(output, "D");
while (i3>0)
{
i3-=1;
strcat(output, "C");
}
}
else
if (i3==4)
{
strcat(output, "CD");
}
else
while (i3>0)
{
i3-=1;
strcat(output, "C");
}
cout << "Output: " << output << endl;
}
if (intput>9) //10-99
{
int i2=(intput / 10 % 10);
cout << "Число десятков: " << i2 << endl;
if (i2==9)
{
strcat(output, "XC");
}
else
if (i2>=5)
{
i2-=5;
strcat(output, "L");
while (i2>0)
{
i2-=1;
strcat(output, "X");
}
}
else
if (i2==4)
{
strcat(output, "XL");
}
else
while (i2>0)
{
i2-=1;
strcat(output, "X");
}
cout << "Output: " << output << endl;
}
if (intput>0) //1-9
{
int i1=(intput % 10);
cout << "Число единиц: " << i1 << endl;
if (i1==9)
{
strcat(output, "IX");
}
else
if (i1>=5)
{
i1-=5;
strcat(output, "V");
while (i1>0)
{
i1-=1;
strcat(output, "I");
}
}
else
if (i1==4)
{
strcat(output, "IV");
}
else
while (i1>0)
{
i1-=1;
strcat(output, "I");
}
cout << "Output: " << output << endl;
}
if (intput==0) cout << "Ноль? Он обозначается так: —" << endl;
cout << endl << "Римская запись числа " << input << ": " << output << "." << endl;
}
}
system("pause");
} |
|
Во время компиляции выводится предупреждение:
-[BCC32 Warning] File1.cpp(19): W8012 Comparing signed and unsigned values
*-Full parser context
**-File1.cpp(10): parsing: void ex8()
Мудрецы, чего я не вижу?
0
|