Hello, currently new to C++ and learning the ropes.
I'm trying to create a simple database-like program, but the following code doesn't output any meaningful data. The program compiles fine, though.

The rest of the program is still under work, so I'm just posting the relevant parts which I think are related to the problem:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

//Entering protofunctions first
void UserVerif ();
void UserCreate();
void PayVerif ();
void NameVerif();
void OrderTake ();
void OrderVerif (); 

class ProdRecord
{
      public:
      string name;
      float price;
      int stock;
      ProdRecord(string name, float price, int stock)
      {}  
};

void OrderTake()
{
       int ordertin;
       vector<ProdRecord>products;
       
       products.push_back(ProdRecord("Diablo 3", 150.00, 0));
       products.push_back(ProdRecord("Call of Duty 5", 150.00, 20));
       products.push_back(ProdRecord("Starcraft 3", 150.00, 30));
       products.push_back(ProdRecord("Battlefield 4", 150.00, 30));
       products.push_back(ProdRecord("Warcraft 4", 150.00, 25));
       products.push_back(ProdRecord("Catz 'N Dogz", 50.00, 100));
     
       system("cls");
       cout << "Please select your desired product:" << endl;
       cout << "1. " << products[0].name << "RM" << products[0].price << "STOCK= " << products[0].stock << endl;
       cout << "2. " << products[1].name << "RM" << products[1].price << "STOCK= " << products[1].stock << endl;
       cout << "3. " << products[2].name << "RM" << products[2].price << "STOCK= " << products[2].stock << endl;
       cout << "4. " << products[3].name << "RM" << products[3].price << "STOCK= " << products[3].stock << endl;
       cout << "5. " << products[4].name << "RM" << products[4].price << "STOCK= " << products[4].stock << endl;
       cout << "6. " << products[5].name << "RM" << products[5].price << "STOCK= " << products[5].stock << endl;
       cout << "Please enter 1-6 for the product of your choice." << endl;
       cin >> ordertin;
}

int main()
{
    OrderTake ();
    
    system ("pause");
    return 0;
}
Re: Unable to output data from vector 80 80

Hello, currently new to C++ and learning the ropes.
I'm trying to create a simple database-like program, but the following code doesn't output any meaningful data. The program compiles fine, though.

The rest of the program is still under work, so I'm just posting the relevant parts which I think are related to the problem:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

//Entering protofunctions first
void UserVerif ();
void UserCreate();
void PayVerif ();
void NameVerif();
void OrderTake ();
void OrderVerif (); 

class ProdRecord
{
      public:
      string name;
      float price;
      int stock;
      [CODE]ProdRecord(string name, float price, int stock)
      {}  [/CODE]};

void OrderTake()
{
       int ordertin;
       vector<ProdRecord>products;

       products.push_back(ProdRecord("Diablo 3", 150.00, 0));
       products.push_back(ProdRecord("Call of Duty 5", 150.00, 20));
       products.push_back(ProdRecord("Starcraft 3", 150.00, 30));
       products.push_back(ProdRecord("Battlefield 4", 150.00, 30));
       products.push_back(ProdRecord("Warcraft 4", 150.00, 25));
       products.push_back(ProdRecord("Catz 'N Dogz", 50.00, 100));

       system("cls");
       cout << "Please select your desired product:" << endl;
       cout << "1. " << products[0].name << "RM" << products[0].price << "STOCK= " << products[0].stock << endl;
       cout << "2. " << products[1].name << "RM" << products[1].price << "STOCK= " << products[1].stock << endl;
       cout << "3. " << products[2].name << "RM" << products[2].price << "STOCK= " << products[2].stock << endl;
       cout << "4. " << products[3].name << "RM" << products[3].price << "STOCK= " << products[3].stock << endl;
       cout << "5. " << products[4].name << "RM" << products[4].price << "STOCK= " << products[4].stock << endl;
       cout << "6. " << products[5].name << "RM" << products[5].price << "STOCK= " << products[5].stock << endl;
       cout << "Please enter 1-6 for the product of your choice." << endl;
       cin >> ordertin;
}

int main()
{
    OrderTake ();

    system ("pause");
    return 0;
}           

end quote.

You forgot to initialize your variables in your class constructor. You need to do

ProdRecord(string n, float p, int s)
      {nsme = n; price = p; stock = s;}  

or

ProdRecord(string n, float p, int s) : name(n), price(p), stock(s) 
      {}  
Re: Unable to output data from vector 80 80

Ah yes, that worked. Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.