array or int

This is a discussion on array or int within the C++ Programming forums, part of the General Programming Boards category; Okay I want to make a program were the user inputs a name of an item and the proce of ...

  1. #1
    using namespace Trooper; St0rmTroop3er's Avatar
    Join Date
    Sep 2003
    Posts
    77

    array or int

    Okay I want to make a program were the user inputs a name of an item and the proce of the item than keeps doing it till the user want to stop. Now my question is how should I store the users input? through multable varables...



    Code:
    char ItemOne
    int itemPriceOne
    or use arays


    Code:
    string itemname[128]
    int itemprice[128]
    
    int main()
    {
    
     cout << "Enter item name: "
     cin << itemname[1]
     
    
    if(itemname[1] = "done")
    {
     displayinfo(void)
    }
    else
    {
    
     main()
    }
    now that isn't my finle program it is just an idea of what i want to do. So should I use varables or arrays?

    ~StormTrooper

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Well you could use some other container like linked list or vector :P...but I assume you are new to C++ so it would probably be a good idea to use an array, if only to get a better understanding of how to use them. Also if you use an array you can use a variable that is incremented in each loop to access/change the element:
    Code:
    for (int i=0;i<lgnthOfArray;i++)
    {
      ...
      cin>>array[i];
    }
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    using namespace Trooper; St0rmTroop3er's Avatar
    Join Date
    Sep 2003
    Posts
    77
    Code:
    for (int i=0;i<lgnthOfArray;i++)
    {
      ...
      cin>>array[i];
    }

    okay do i need to int lgnthOfArray int it? so the code would be...



    Code:
    int IN; //Int Item name
    
    int IP; // int Item Price
    
    int main()
    {
    
    cout << "Enter in a Product Name: ";
    cin >> ItemName[IN];
    
    cout << "Enter in the products price: $ ";
    cin >> ItemPrice[IP]
    
    IN++;
    IP++;
    
    for (i <= 10) || (ItemName[I] = "Done") || (ItemName[i] = "done")
    {
     displayInfo(void)
    
    }
    right?
    Last edited by St0rmTroop3er; 09-04-2003 at 07:46 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 11:36 AM
  3. problem with sorting
    By pinkpenguin in forum C Programming
    Replies: 2
    Last Post: 11-18-2005, 10:06 AM
  4. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 05:20 AM
  5. easy if you know how to use functions...
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 01-31-2002, 06:34 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21