So I'm trying to make a program to pull the last 2 numbers off a 5 digit number and output the corresponding color with the number.The program won't run and comes back with this error located at the bottom.
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
|
#include <iostream>
#include <string>
using namespace std;
int main()
{
string invcode;
cout<< "Enter the 5 digit inventory code: ";
cin>>invcode;
if(invcode.substr(3,2)=41)
{
cout<<"Red"<<endl;
}
else if(invcode.substr(3,2)=25)
{
cout<<"Black"<<endl;
}
else if(invcode.substr(3,2)=30)
{
cout<<"Green"<<endl;
}
else
{
cout<<"Invalid inventory code"<<endl;
}
system("pause");
return 0;
}
|
17|error: could not convert `(&std::basic_string<_CharT, _Traits, _Alloc>::substr(typename _Alloc::size_type, typename _Alloc::size_type) const [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](3u, 2u))->std::basic_string<_CharT, _Traits, _Alloc>::operator= [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((const char*)"41"))' to `bool'|
C:\Users\Showdon\Desktop\C++\Lab15\Lab1501\main.cpp|21|error: could not convert `(&std::basic_string<_CharT, _Traits, _Alloc>::substr(typename _Alloc::size_type, typename _Alloc::size_type) const [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](3u, 2u))->std::basic_string<_CharT, _Traits, _Alloc>::operator= [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](25)' to `bool'|
C:\Users\Showdon\Desktop\C++\Lab15\Lab1501\main.cpp|25|error: could not convert `(&std::basic_string<_CharT, _Traits, _Alloc>::substr(typename _Alloc::size_type, typename _Alloc::size_type) const [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](3u, 2u))->std::basic_string<_CharT, _Traits, _Alloc>::operator= [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](30)' to `bool'|
||=== Build finished: 3 errors, 0 warnings ===|