-1

Hello can anyone help me with my assignment...i don't understand how to correct the error All details shown below

#include <iostream>
#include <string>
using namespace std;

int main()
{
    string packageCode, packageCode1, packageCode2, packageCode3, 
AKFM101, ADFM102, KDFM103, maskColour;
    int quantity_set_of_mask;
    cout << "Enter Package Code [AKFM101 , ADFM102 , KDFM103] = ";
    cin >> packageCode;
    if (packageCode=AKFM101);
        packageCode1=AKFM101;

    if (packageCode=ADFM102)
        packageCode2=ADFM102;

    if (packageCode=KDFM103)
        packageCode3=KDFM103;
    
    cout << "Enter Quantity Set Of Mask = ";
    cin >> quantity_set_of_mask;
    cout << "Enter Mask Colour [Blue , Yellow] = ";
    cin >> maskColour;

}

Above I share my coding using C++ language....but I get this error

[Error] could not convert 'packageCode.std::basic_string<_CharT, _Traits,
_Alloc>::operator=<char, std::char_traits<char>, std::allocator<char> >((*
(const std::basic_string<char>*)(& AKFM101)))' from 
'std::basic_string<char>' to 'bool'

Hope someone can help me with my work

A_H
  • 1

1 Answers1

1

= operator is use for assignment. For comparision, use the == operator.

Also:

if (packageCode == AKFM101);
    packageCode1 = AKFM101;

Will get evaluate to:

if (packageCode == AKFM101)
{
    ;
}
packageCode1 = AKFM101;

So packageCode1 = AKFM101; will always run even if packageCode == AKFM101 is false. You should remove the semicolon.

Overall, your if statement should be like this:

if (packageCode == AKFM101)
    packageCode1 = AKFM101;

if (packageCode == ADFM102)
    packageCode2 = ADFM102;

if (packageCode == KDFM103)
    packageCode3 = KDFM103;

Note: using namespace std; is bad practice, so avoid using it.