Форум программистов, компьютерный форум, киберфорум
С++ для начинающих
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.52/25: Рейтинг темы: голосов - 25, средняя оценка - 4.52
0 / 0 / 1
Регистрация: 04.05.2014
Сообщений: 21
1

Не вызывается функция

12.02.2015, 22:03. Показов 5072. Ответов 3
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Когда код функции находился в главной функции, то выполнялся без нареканий(не считая выскакивания из цикла, если превысить длину входящий строки), когда попытался перенести его в функцию 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
Лучшие ответы (1)
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
12.02.2015, 22:03
Ответы с готовыми решениями:

Не вызывается функция
Здравствуйте. Не понимаю почему, но код работает, а программа даже не заходит в функцию. В чем...

Не вызывается функция?
int main() { cout&lt;&lt;&quot;Let's go!\n\n\n&quot;; int Fill_array(); } int Fill_array(double...

Не вызывается функция
Здравствуйте. Не работает условие в цикле. Просто не вызывается функция prior. Как исправить? int...

Не вызывается функция из функции
Добрый вечер! Пытаюсь вызвать функцию add из функции i, но вылезает ошибка. В чём дело? Помогите,...

3
Модератор
Эксперт С++
13507 / 10757 / 6412
Регистрация: 18.12.2011
Сообщений: 28,712
12.02.2015, 22:05 2
Лучший ответ Сообщение было отмечено SanyaClaus как решение

Решение

Не ex8;
а
C++
1
ex8();
1
0 / 0 / 1
Регистрация: 04.05.2014
Сообщений: 21
12.02.2015, 22:07  [ТС] 3
При дебагинге после строчки
C++
1
SetConsoleOutputCP(1251);
происходит переход сразу к
C++
1
system("pause");
.
0
Модератор
Эксперт по электронике
8908 / 6677 / 918
Регистрация: 14.02.2011
Сообщений: 23,521
12.02.2015, 22:11 4
Цитата Сообщение от SanyaClaus Посмотреть сообщение
void ex8()
C++
1
void ex8(void)
Цитата Сообщение от SanyaClaus Посмотреть сообщение
ex8;
C++
1
ex8();
иначе он не поймет что вызывается функция

Добавлено через 1 минуту
Цитата Сообщение от SanyaClaus Посмотреть сообщение
**-File1.cpp(10): parsing: void ex8()
раз функция не вызывается значит лишняя, выбросим
1
12.02.2015, 22:11
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
12.02.2015, 22:11
Помогаю со студенческими работами здесь

Не вызывается дружественная функция
Создал класс, есть дружественная функция: int NOD(int a,int b) { while(b) { ...

Функция не вызывается 2й раз
Смысл - функция служит для записи числа в массив (посимвольно) int* read(int mass) { int...

Не вызывается функция GetComputerName
#include &lt;windows.h&gt; #include &lt;iostream&gt; using namespace std; #ifndef _MAC #define...

Когда какая функция вызывается?
Вот две функции const Item &amp;figure::operator (int i) const { cout &lt;&lt; &quot;const&quot; &lt;&lt; endl; ...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
4
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru