Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > C/C++ программирование > Общие вопросы C/C++
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 09.12.2018, 22:40   #1
Blacit
 
Регистрация: 09.12.2018
Сообщений: 8
По умолчанию Самый простой компилятор

В чём ошибка?


Код:
#include <iostream>
 
using namespace std;
 
    using std:cout; using std::cin;
    float sm, E, tm, sv, tv;
    const int M = 100;
    const int CM = 1;
    const float F = 30.48;
    const float Inch = 2.54;
    
int main()
{
    setlocal(0, "russian");
    cout << "Выберите размер входной величины: ";
    cout << "1) CM" <<endl;
    cout << "2) Inch" <<endl;
    cout << "3) Feet" <<endl;
    cout << "4) Metr" <<endl;
    cin >> cin sm;
    cout << "Выберите размер выходной величины: ";
    cout << "1) CM" <<endl;
    cout << "2) Inch" <<endl;
    cout << "3) Feet" <<endl;
    cout << "4) Metr" <<endl;
    cin >> tm;
    
    cout << "Введите величину: "
    cin >> sv;
    
    E = (sm - 1) * 4 + (tm - 1);
    
    tv = (
    (E==0) * (sv) +
    (E==1) * (sv * 1) +
    (E==2) * (sv * 0.39f) +
    (E==3) * (sv * 0.001f) +
    (E==4) * (sv * 1/2.4f) +
    (E==5) * (sv * 2.54f) +
    (E==6) * (sv * 1) +
    (E==7) * (sv * 0.833f) +
    (E==8) * (sv * 0.0254f) +
    (E==9) * (sv * 30.48f) +
    (E==10) * (sv * 12f) +
    (E==11) * (sv * 1) +
    (E==12) * (sv * 0.3048f) +
    (E==13) * (sv * 100) +
    (E==14) * (sv * 39,37f) +
    (E==15) * (sv * 0.3048f) +
    (E==16) * (sv * 1) +
    )
    return 0;
}
Blacit вне форума Ответить с цитированием
Старый 09.12.2018, 22:45   #2
p51x
Старожил
 
Регистрация: 15.02.2010
Сообщений: 15,706
По умолчанию

Код:
prog.cpp:5:14: error: found ‘:’ in nested-name-specifier, expected ‘::’
     using std:cout; using std::cin;
              ^
prog.cpp: In function ‘int main()’:
prog.cpp:14:26: error: ‘setlocal’ was not declared in this scope
     setlocal(0, "russian");
                          ^
prog.cpp:20:9: error: no match for ‘operator>>’ (operand types are ‘std::istream {aka std::basic_istream<char>}’ and ‘std::istream {aka std::basic_istream<char>}’)
     cin >> cin sm;
     ~~~~^~~~~~
prog.cpp:20:9: note: candidate: operator>>(int, int) <built-in>
prog.cpp:20:9: note:   no known conversion for argument 2 from ‘std::istream {aka std::basic_istream<char>}’ to ‘int’
In file included from /usr/include/c++/6/iostream:40:0,
                 from prog.cpp:1:
/usr/include/c++/6/istream:120:7: note: candidate: std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>::__istream_type& (*)(std::basic_istream<_CharT, _Traits>::__istream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]
       operator>>(__istream_type& (*__pf)(__istream_type&))
       ^~~~~~~~
/usr/include/c++/6/istream:120:7: note:   no known conversion for argument 1 from ‘std::istream {aka std::basic_istream<char>}’ to ‘std::basic_istream<char>::__istream_type& (*)(std::basic_istream<char>::__istream_type&) {aka std::basic_istream<char>& (*)(std::basic_istream<char>&)}’
/usr/include/c++/6/istream:124:7: note: candidate: std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>::__ios_type& (*)(std::basic_istream<_CharT, _Traits>::__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>; std::basic_istream<_CharT, _Traits>::__ios_type = std::basic_ios<char>]
       operator>>(__ios_type& (*__pf)(__ios_type&))
       ^~~~~~~~
/usr/include/c++/6/istream:124:7: note:   no known conversion for argument 1 from ‘std::istream {aka std::basic_istream<char>}’ to ‘std::basic_istream<char>::__ios_type& (*)(std::basic_istream<char>::__ios_type&) {aka std::basic_ios<char>& (*)(std::basic_ios<char>&)}’
/usr/include/c++/6/istream:131:7: note: candidate: std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]
       operator>>(ios_base& (*__pf)(ios_base&))
       ^~~~~~~~
/usr/include/c++/6/istream:131:7: note:   no known conversion for argument 1 from ‘std::istream {aka std::basic_istream<char>}’ to ‘std::ios_base& (*)(std::ios_base&)’
/usr/include/c++/6/istream:168:7: note: candidate: std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]
       operator>>(bool& __n)
       ^~~~~~~~
/usr/include/c++/6/istream:168:7: note:   no known conversion for argument 1 from ‘std::istream {aka std::basic_istream<char>}’ to ‘bool&’
/usr/include/c++/6/istream:172:7: note: candidate: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char; _Traits = std::char_traits<char>]
       operator>>(short& __n);
       ^~~~~~~~
/usr/include/c++/6/istream:172:7: note:   no known conversion for argument 1 from ‘std::istream {aka std::basic_istream<char>}’ to ‘short int&’
/usr/include/c++/6/istream:175:7: note: candidate: std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]
       operator>>(unsigned short& __n)
       ^~~~~~~~
/usr/include/c++/6/istream:175:7: note:   no known conversion for argument 1 from ‘std::istream {aka std::basic_istream<char>}’ to ‘short unsigned int&’
/usr/include/c++/6/istream:179:7: note: candidate: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char; _Traits = std::char_traits<char>]
       operator>>(int& __n);
       ^~~~~~~~
/usr/include/c++/6/istream:179:7: note:   no known conversion for argument 1 from ‘std::istream {aka std::basic_istream<char>}’ to ‘int&’
/usr/include/c++/6/istream:182:7: note: candidate: std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]
       operator>>(unsigned int& __n)
       ^~~~~~~~
/usr/include/c++/6/istream:182:7: note:   no known conversion for argument 1 from ‘std::istream {aka std::basic_istream<char>}’ to ‘unsigned int&’
/usr/include/c++/6/istream:186:7: note: candidate: std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]
       operator>>(long& __n)
       ^~~~~~~~
/usr/include/c++/6/istream:186:7: note:   no known conversion for argument 1 from ‘std::istream {aka std::basic_istream<char>}’ to ‘long int&’
/usr/include/c++/6/istream:190:7: note: candidate: std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]
       operator>>(unsigned long& __n)
       ^~~~~~~~
/usr/include/c++/6/istream:190:7: note:   no known conversion for argument 1 from ‘std::istream {aka std::basic_istream<char>}’ to ‘long unsigned int&’
/usr/include/c++/6/istream:195:7: note: candidate: std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]
p51x вне форума Ответить с цитированием
Старый 09.12.2018, 22:46   #3
p51x
Старожил
 
Регистрация: 15.02.2010
Сообщений: 15,706
По умолчанию

Код:
       operator>>(long long& __n)
       ^~~~~~~~
/usr/include/c++/6/istream:195:7: note:   no known conversion for argument 1 from ‘std::istream {aka std::basic_istream<char>}’ to ‘long long int&’
/usr/include/c++/6/istream:199:7: note: candidate: std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]
       operator>>(unsigned long long& __n)
       ^~~~~~~~
/usr/include/c++/6/istream:199:7: note:   no known conversion for argument 1 from ‘std::istream {aka std::basic_istream<char>}’ to ‘long long unsigned int&’
/usr/include/c++/6/istream:214:7: note: candidate: std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(float&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]
       operator>>(float& __f)
       ^~~~~~~~
/usr/include/c++/6/istream:214:7: note:   no known conversion for argument 1 from ‘std::istream {aka std::basic_istream<char>}’ to ‘float&’
/usr/include/c++/6/istream:218:7: note: candidate: std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(double&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]
       operator>>(double& __f)
       ^~~~~~~~
/usr/include/c++/6/istream:218:7: note:   no known conversion for argument 1 from ‘std::istream {aka std::basic_istream<char>}’ to ‘double&’
/usr/include/c++/6/istream:222:7: note: candidate: std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long double&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]
       operator>>(long double& __f)
       ^~~~~~~~
/usr/include/c++/6/istream:222:7: note:   no known conversion for argument 1 from ‘std::istream {aka std::basic_istream<char>}’ to ‘long double&’
/usr/include/c++/6/istream:235:7: note: candidate: std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]
       operator>>(void*& __p)
       ^~~~~~~~
/usr/include/c++/6/istream:235:7: note:   no known conversion for argument 1 from ‘std::istream {aka std::basic_istream<char>}’ to ‘void*&’
/usr/include/c++/6/istream:259:7: note: candidate: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>::__streambuf_type*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__streambuf_type = std::basic_streambuf<char>]
p51x вне форума Ответить с цитированием
Старый 09.12.2018, 22:46   #4
p51x
Старожил
 
Регистрация: 15.02.2010
Сообщений: 15,706
По умолчанию

Код:
operator>>(__streambuf_type* __sb);
       ^~~~~~~~
/usr/include/c++/6/istream:259:7: note:   no known conversion for argument 1 from ‘std::istream {aka std::basic_istream<char>}’ to ‘std::basic_istream<char>::__streambuf_type* {aka std::basic_streambuf<char>*}’
In file included from /usr/include/c++/6/string:53:0,
                 from /usr/include/c++/6/bits/locale_classes.h:40,
                 from /usr/include/c++/6/bits/ios_base.h:41,
                 from /usr/include/c++/6/ios:42,
                 from /usr/include/c++/6/ostream:38,
                 from /usr/include/c++/6/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/6/bits/basic_string.tcc:1437:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
     operator>>(basic_istream<_CharT, _Traits>& __in,
     ^~~~~~~~
/usr/include/c++/6/bits/basic_string.tcc:1437:5: note:   template argument deduction/substitution failed:
prog.cpp:20:12: note:   ‘std::istream {aka std::basic_istream<char>}’ is not derived from ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
     cin >> cin sm;
            ^~~
In file included from /usr/include/c++/6/istream:934:0,
                 from /usr/include/c++/6/iostream:40,
                 from prog.cpp:1:
/usr/include/c++/6/bits/istream.tcc:955:5: note: candidate: template<class _CharT2, class _Traits2> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, _CharT2*)
     operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s)
     ^~~~~~~~
/usr/include/c++/6/bits/istream.tcc:955:5: note:   template argument deduction/substitution failed:
prog.cpp:20:12: note:   mismatched types ‘_CharT2*’ and ‘std::basic_istream<char>’
     cin >> cin sm;
            ^~~
In file included from /usr/include/c++/6/istream:934:0,
                 from /usr/include/c++/6/iostream:40,
                 from prog.cpp:1:
/usr/include/c++/6/bits/istream.tcc:923:5: note: candidate: template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, _CharT&)
     operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c)
     ^~~~~~~~
/usr/include/c++/6/bits/istream.tcc:923:5: note:   template argument deduction/substitution failed:
prog.cpp:20:12: note:   deduced conflicting types for parameter ‘_CharT’ (‘char’ and ‘std::istream {aka std::basic_istream<char>}’)
     cin >> cin sm;
            ^~~
In file included from /usr/include/c++/6/iostream:40:0,
                 from prog.cpp:1:
/usr/include/c++/6/istream:756:5: note: candidate: template<class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, unsigned char&)
     operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c)
     ^~~~~~~~
/usr/include/c++/6/istream:756:5: note:   template argument deduction/substitution failed:
prog.cpp:20:12: note:   cannot convert ‘std::cin’ (type ‘std::istream {aka std::basic_istream<char>}’) to type ‘unsigned char&’
     cin >> cin sm;
            ^~~
In file included from /usr/include/c++/6/iostream:40:0,
                 from prog.cpp:1:
/usr/include/c++/6/istream:761:5: note: candidate: template<class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, signed char&)
     operator>>(basic_istream<char, _Traits>& __in, signed char& __c)
     ^~~~~~~~
/usr/include/c++/6/istream:761:5: note:   template argument deduction/substitution failed:
prog.cpp:20:12: note:   cannot convert ‘std::cin’ (type ‘std::istream {aka std::basic_istream<char>}’) to type ‘signed char&’
     cin >> cin sm;
            ^~~
In file included from /usr/include/c++/6/iostream:40:0,
                 from prog.cpp:1:
/usr/include/c++/6/istream:803:5: note: candidate: template<class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, unsigned char*)
     operator>>(basic_istream<char, _Traits>& __in, unsigned char* __s)
     ^~~~~~~~
/usr/include/c++/6/istream:803:5: note:   template argument deduction/substitution failed:
prog.cpp:20:12: note:   cannot convert ‘std::cin’ (type ‘std::istream {aka std::basic_istream<char>}’) to type ‘unsigned char*’
     cin >> cin sm;
            ^~~
In file included from /usr/include/c++/6/iostream:40:0,
                 from prog.cpp:1:
/usr/include/c++/6/istream:808:5: note: candidate: template<class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, signed char*)
     operator>>(basic_istream<char, _Traits>& __in, signed char* __s)
     ^~~~~~~~
/usr/include/c++/6/istream:808:5: note:   template argument deduction/substitution failed:
prog.cpp:20:12: note:   cannot convert ‘std::cin’ (type ‘std::istream {aka std::basic_istream<char>}’) to type ‘signed char*’
     cin >> cin sm;
            ^~~
In file included from /usr/include/c++/6/iostream:40:0,
                 from prog.cpp:1:
/usr/include/c++/6/istream:924:5: note: candidate: std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&&, _Tp&) [with _CharT = char; _Traits = std::char_traits<char>; _Tp = std::basic_istream<char>] <near match>
     operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x)
     ^~~~~~~~
/usr/include/c++/6/istream:924:5: note:   conversion of argument 1 would be ill-formed:
prog.cpp:20:12: error: cannot bind ‘std::istream {aka std::basic_istream<char>}’ lvalue to ‘std::basic_istream<char>&&’
     cin >> cin sm;
            ^~~
prog.cpp:29:5: error: expected ‘;’ before ‘cin’
     cin >> sv;
     ^~~
prog.cpp:44:21: error: unable to find numeric literal operator ‘operator""f’
     (E==10) * (sv * 12f) +
                     ^~~
prog.cpp:48:24: error: unable to find numeric literal operator ‘operator""f’
     (E==14) * (sv * 39,37f) +
                        ^~~
prog.cpp:51:5: error: expected primary-expression before ‘)’ token
     )
     ^
p51x вне форума Ответить с цитированием
Старый 09.12.2018, 23:06   #5
Blacit
 
Регистрация: 09.12.2018
Сообщений: 8
По умолчанию

Переделал. Но до сих пор есть ошибки. Как их исправить?

Код:
#include <iostream>

using namespace std;

    using std::cout; using std::cin;
    float sm, E, tm, sv, tv;
    const int M = 100;
    const int CM = 1;
    const float F = 30.48;
    const float Inch = 2.54;
    
int main()
{
    cout << "Select size input size: ";
    cout << "1) CM" <<endl;
    cout << "2) Inch" <<endl;
    cout << "3) Feet" <<endl;
    cout << "4) Metr" <<endl;
    cin >> cin sm;
    cout << "Select the size of the output value: ";
    cout << "1) CM" <<endl;
    cout << "2) Inch" <<endl;
    cout << "3) Feet" <<endl;
    cout << "4) Metr" <<endl;
    cin >> tm;
    
    cout << "Enter a value:";
    cin >> sv;
    
    E = (sm - 1) * 4 + (tm - 1);
    
    tv = (
    (E==0) * (sv) +
    (E==1) * (sv * 1) +
    (E==2) * (sv * 0.39f) +
    (E==3) * (sv * 0.001f) +
    (E==4) * (sv * 1/2.4f) +
    (E==5) * (sv * 2.54f) +
    (E==6) * (sv * 1) +
    (E==7) * (sv * 0.833f) +
    (E==8) * (sv * 0.0254f) +
    (E==9) * (sv * 30.48f) +
    (E==10) * (sv * 12f) +
    (E==11) * (sv * 1) +
    (E==12) * (sv * 0.3048f) +
    (E==13) * (sv * 100) +
    (E==14) * (sv * 39.37f) +
    (E==15) * (sv * 0.3048f) +
    (E==16) * (sv * 1) +
    )
    return 0;
}
Blacit вне форума Ответить с цитированием
Старый 09.12.2018, 23:22   #6
BDA
МегаМодератор
СуперМодератор
 
Аватар для BDA
 
Регистрация: 09.11.2010
Сообщений: 7,289
По умолчанию

Не надо из cin в cin писать. Уберите f у целого числа. Поставьте точку с запятой после последней круглой скобки.
Пишите язык программирования - это форум программистов, а не экстрасенсов. (<= это подпись )
BDA на форуме Ответить с цитированием
Старый 10.12.2018, 00:07   #7
Blacit
 
Регистрация: 09.12.2018
Сообщений: 8
По умолчанию

Цитата:
Сообщение от BDA Посмотреть сообщение
Не надо из cin в cin писать. Уберите f у целого числа. Поставьте точку с запятой после последней круглой скобки.
Код, который есть на данный момент:

Код:
#include <iostream>
 
using namespace std;
 
    float sm, E, tm, sv, tv;
    const int M = 100;
    const int CM = 1;
    const float F = 30.48;
    const float Inch = 2.54;
    
int main()
{
    cout << "Select size input size: " <<endl;;
    cout << "1) CM" <<endl;
    cout << "2) Inch" <<endl;
    cout << "3) Feet" <<endl;
    cout << "4) Metr" <<endl;
    cin >>  sm;
    cout << "Select the size of the output value: " <<endl;
    cout << "1) CM" <<endl;
    cout << "2) Inch" <<endl;
    cout << "3) Feet" <<endl;
    cout << "4) Metr" <<endl;
    cin >> tm;
    
    cout << "Enter a value:";
    cin >> sv;
    
    E = (sm - 1) * 4 + (tm - 1);
    
    tv = (
    (E==0) * (sv) +
    (E==1) * (sv * 1) +
    (E==2) * (sv * 0.39f) +
    (E==3) * (sv * 0.001f) +
    (E==4) * (sv * 1/2.4f) +
    (E==5) * (sv * 2.54f) +
    (E==6) * (sv * 1) +
    (E==7) * (sv * 0.833f) +
    (E==8) * (sv * 0.0254f) +
    (E==9) * (sv * 30.48f) +
    (E==10) * (sv * 12) +
    (E==11) * (sv * 1) +
    (E==12) * (sv * 0.3048f) +
    (E==13) * (sv * 100) +
    (E==14) * (sv * 39.37f) +
    (E==15) * (sv * 0.3048f) +
    (E==16) * (sv * 1)
    );
    
    cout << "Result: " << tv << endl;
    return 0;
}
Blacit вне форума Ответить с цитированием
Старый 10.12.2018, 01:10   #8
jillitil
Форумчанин
 
Аватар для jillitil
 
Регистрация: 17.10.2018
Сообщений: 184
По умолчанию

Замудрили с tv, всего 16 вариантов, а настрочили 17. sv == sv*1 значит "сдвинуть" формулу надо на -1 и удалить первый элемент.
И вообще зачем вводили константы если их не использовали? Такая хрень жрёт много вычислительных ресурсов.
jillitil вне форума Ответить с цитированием
Старый 10.12.2018, 01:16   #9
Blacit
 
Регистрация: 09.12.2018
Сообщений: 8
По умолчанию

Готовый ответ:

Код:
#include <iostream>
 
using namespace std;
 
    double sv, tv;
    unsigned int sm, E, tm;
    
int main()
{
    cout << "Select size input size: " <<endl;
    cout << "1) CM" <<endl;
    cout << "2) Inch" <<endl;
    cout << "3) Feet" <<endl;
    cout << "4) Metr" <<endl;
    cin >>  sm;
    cout << "Select the size of the output value: " <<endl;
    cout << "1) CM" <<endl;
    cout << "2) Inch" <<endl;
    cout << "3) Feet" <<endl;
    cout << "4) Metr" <<endl;
    cin >> tm;
    
    cout << "Enter a value:";
    cin >> sv;
    
    E = (sm - 1) * 4 + (tm - 1);
    
tv = (
    // CM -> CM
    (E==0) * (sv * 1) +
    // CM -> Inch
    (E==1) * (sv * 0.39) +
    // CM -> Feet
    (E==2) * (sv * 0.01) +
    // CM -> Metr
    (E==3) * (sv * 1/2.4) +
    // Inch -> CM
    (E==4) * (sv * 2.54) +
    // Inch -> CInch
    (E==5) * (sv * 1) +
    // Inch -> Feet
    (E==6) * (sv * 0.833) +
    // Inch -> Metr
    (E==7) * (sv * 0.0254) +
    // Feet -> CM
    (E==8) * (sv * 30.48) +
    // Feet -> Inch
    (E==9) * (sv * 12.0) +
    // Feet -> Feet
    (E==10) * (sv * 1) +
    // Feet -> Metr
    (E==11) * (sv * 0.3048) +
    // Metr -> CM
    (E==12) * (sv * 100) +
    // Metr -> Inch
    (E==13) * (sv * 39.37) +
    // Metr -> Feet
    (E==14) * (sv * 0.3048) +
    // Metr -> Metr
    (E==15) * (sv * 1)
    );
    
    cout << "Result: " << tv << endl;
    return 0;
}
Blacit вне форума Ответить с цитированием
Старый 10.12.2018, 08:44   #10
BDA
МегаМодератор
СуперМодератор
 
Аватар для BDA
 
Регистрация: 09.11.2010
Сообщений: 7,289
По умолчанию

Кое-где коэффициенты перепутаны. Можно чуть сократить код, написав:
Код:
(sm == tm) * sv +
// CM -> Inch
(E==1) * (sv * 0.39) +
// ... остальные случаи, кроме тех, где не требуется перевод
Пишите язык программирования - это форум программистов, а не экстрасенсов. (<= это подпись )
BDA на форуме Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Самый простой поиск Fanar БД в Delphi 5 15.03.2011 19:26
Самый простой пример J-Max C++ Builder 1 03.12.2010 22:59
Самый простой способ сравнения. Mixasik Общие вопросы Delphi 6 21.04.2010 12:04
Не работает самый простой триггер nazavrik SQL, базы данных 2 11.06.2009 17:30