473,326 Members | 2,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

C++ Array Question

I am trying to take the following instructions and make it a working code. The instructions were to use appropriate data types, and all dara types are represented as either numeric or string.

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
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using std::cout;
  5. using std::cin;
  6. using std::endl;
  7. using std::string;
  8.  
  9.  
  10. int main()
  11. {
  12.     //declare variables and arrays
  13.     string name = "";
  14.     string address = "";
  15.     int item = 0;
  16.     int quantity = 0;
  17.     double price = 0.00;
  18.     const int SIZE = 6;
  19.     int VALID_ITEM[SIZE] = {106, 108, 307, 405, 457, 688};
  20.     double VALID_ITEM_PRICE[SIZE] = {0.59, 0.99, 4.50, 15.99, 17.50, 39.00};
  21.     int sub;
  22.     string foundIt = "N";
  23.     string MSG_YES = "Item available";
  24.     string MSG_NO = "Item not found";
  25.  
  26.     getline (cin, name);
  27.     getline (cin, address);
  28.  
  29.  
  30.     sub = 0;
  31.  
  32.     while (sub < SIZE)
  33.     {
  34.         if (item = VALID_ITEM[sub])
  35.         {
  36.             foundIt = "Y";
  37.             price = VALID_ITEM_PRICE[sub];
  38.         }    //end if
  39.  
  40.         sub = sub + 1;
  41.  
  42.         // end while
  43.  
  44.         if (foundIt = "Y")
  45.         {
  46.             cout << MSG_YES <<;
  47.             cout << quantity << "at " << price << " each"
  48.                  << "Total " << quantity * price;
  49.         }
  50.         else 
  51.             cout << MSG_NO << endl;
  52.     }    //end if
  53.  
  54. }    //end main function
  55.  
I have two errors:

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!
Apr 12 '10 #1
2 1915
whodgson
542 512MB
The while loop seems to be missing a closing brace
Apr 12 '10 #2
you are using = instead of == in both if statements,
if (item = VALID_ITEM[sub])
if (foundIt = "Y")

and the statement may also cause error because of the extra << operator at the end

cout << MSG_YES <<;
Apr 12 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: SilverWolf | last post by:
I need some help with sorting and shuffling array of strings. I can't seem to get qsort working, and I don't even know how to start to shuffle the array. Here is what I have for now: #include...
9
by: buda | last post by:
Hi, I've been wondering for a while now (and always forgot to ask :) what is the exact quote from the Standard that forbids the use of (&array) (when x >= number_of_columns) as stated in the FAQ...
3
by: Pol Bawin | last post by:
Hi All, One : I have a property that get/set a array of an abstract class A By default my array is null In the propertygrid, It is not works correctly when my array is null. (when my array...
11
by: Geoff Cox | last post by:
Hello, I am trying to get a grip on where to place the initialization of two arrays in the code below which was created using Visual C++ 2005 Express Beta 2... private: static array<String^>^...
28
by: anonymous | last post by:
I have couple of questions related to array addresses. As they belong to the same block, I am putting them here in one single post. I hope nobody minds: char array; int address; Questions...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
51
by: Pedro Graca | last post by:
I run into a strange warning (for me) today (I was trying to improve the score of the UVA #10018 Programming Challenge). $ gcc -W -Wall -std=c89 -pedantic -O2 10018-clc.c -o 10018-clc...
7
by: heddy | last post by:
I have an array of objects. When I use Array.Resize<T>(ref Object,int Newsize); and the newsize is smaller then what the array was previously, are the resources allocated to the objects that are...
8
by: T. Wintershoven | last post by:
Hello all, I have a form with some checkboxes. The names of these checkboxes come from an array. When i click the submit button the resultcode doesn't recognize the names when i want to check...
4
by: mab464 | last post by:
I have this code on my WAMP server running on my XP machine if ( isset( $_POST ) ) { for($i=0; $i<count($_POST);$i++) { if ($ans != NULL ) $ans .= ", " . $_POST ; // Not the first...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.