start
string name
string address
num item
num quantity
num price
num SIZE = 6
num VALID_ITEM [SIZE] = 106, 108, 307, 405, 457, 688
num VALID_ITEM_PRICE [SIZE] = 0.59, 0.99, 4.50, 15.99, 17.50, 39.00
num sub
string foundIt = “N”
string MSG_YES = “Item available”
string MSG_NO = “Item not found”
get name, address, item, quantity
sub = 0
while sub < SIZE
if item = VALID_ITEM [sub] then
foundIt = “Y”
price = VALID_ITEM_PRICE [sub]
endif
sub = sub + 1
endwhile
if foundIt = “Y” then
print MSG_YES
print quantity, “ at “ , price, “ each”
print “Total “, quantity * price
else
print MSG_NO
endif
stop
My code...
Expand|Select|Wrap|Line Numbers
- #include <iostream>
- #include <string>
- using std::cout;
- using std::cin;
- using std::endl;
- using std::string;
- int main()
- {
- //declare variables and arrays
- string name = "";
- string address = "";
- int item = 0;
- int quantity = 0;
- double price = 0.00;
- const int SIZE = 6;
- int VALID_ITEM[SIZE] = {106, 108, 307, 405, 457, 688};
- double VALID_ITEM_PRICE[SIZE] = {0.59, 0.99, 4.50, 15.99, 17.50, 39.00};
- int sub;
- string foundIt = "N";
- string MSG_YES = "Item available";
- string MSG_NO = "Item not found";
- getline (cin, name);
- getline (cin, address);
- sub = 0;
- while (sub < SIZE)
- {
- if (item = VALID_ITEM[sub])
- {
- foundIt = "Y";
- price = VALID_ITEM_PRICE[sub];
- } //end if
- sub = sub + 1;
- // end while
- if (foundIt = "Y")
- {
- cout << MSG_YES <<;
- cout << quantity << "at " << price << " each"
- << "Total " << quantity * price;
- }
- else
- cout << MSG_NO << endl;
- } //end if
- } //end main function
references line 44 - error C2451: conditional expression of type 'std::basic_string<_Elem,_Traits,_Ax>' is illegal
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
references line 46 - error C2059: syntax error : ';'
I'm sure it's something simple, but I can not see it. Any help would be appreciated.
Thanks!