Shopping Simulator or whatevs but I don't understand

I'm supposed to make a code that will "contain three arrays. One that contains 10 integer part numbers, one that contains 10 floating-point prices, and one that contains 10 string descriptions corresponding to the part number and price. The arrays can be filled via a loop prompt cycle, or hard-coded constants, or from a disk file (I chose loop prompt cycle) - student choice on the load mechanism. Display the arrays on column format like the following:

Part #---------Description--------------Price
12435---------Pokemon Card Pack----$432.21
35424---------1000-PK Slim JIM------$1234.55
90345---------Supreme Hoodie BLK--$233.90
29458---------Taco Seasoning--------$34.99
but with spaces instead of -
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iomanip>
#include <iostream>
#include "cstdlib"

using namespace std;

int main ()
{
    int part_num [10];
    string desc [10];
    float price [10];
    int PartCount;
    
    do
    {
        cout << "Number of Items (10 max): ";
        cin >> PartCount;
    }
    while ((PartCount > 10) || (PartCount < 1));
    for (int i = 0; i < PartCount; i++)
    {cout << endl << endl << "Ïtem " << i+1 << "of " << PartCount << endl << endl;
    cout << "Enter Part Number: ";
    cin >> part_num [i];
    cout << "Enter Item Name: ";
    cin >> desc [i];
    cout << "Enter Price: ";
    cin >> price [i];
    }
    cout << endl << endl << endl;
    cout << setw(15) << "Part #" << setw(35) << "Item Name" << setw(18) << "Price" << endl;
    for (int i = 0; i < PartCount; i++)
    {
        cout << setw(15) << part_num [i] << setw(35) << desc [i] << setw(15) << "$" << price [i] << endl;
    }
    return 0;
}


Every time I run it, It just stops after getting the number of items. Can Someone please help me?
Last edited on
Hello LilXeno,

First your program would be a lot easier to read like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iomanip>
#include <iostream>
#include <string>  // <--- Added.
#include "cstdlib"

//using namespace std;

int main()
{
	int part_num[10];
	std::string desc[10];
	float price[10];
	int PartCount;

	do
	{
		std::cout << "Number of Items (10 max): ";
		std::cin >> PartCount;
	} while ((PartCount > 10) || (PartCount < 1));

	for (int i = 0; i < PartCount; i++)
	{
		std::cout << std::endl << std::endl << "Ïtem " << i + 1 << "of " << PartCount << std::endl << std::endl;
		std::cout << "Enter Part Number: ";
		std::cin >> part_num[i];
		std::cout << "Enter Item Name: ";
		std::cin >> desc[i];
		std::cout << "Enter Price: ";
		std::cin >> price[i];
	}

	std::cout << std::endl << std::endl << std::endl;

	std::cout << std::setw(15) << "Part #" << std::setw(35) << "Item Name" << std::setw(18) << "Price" << std::endl;
	
	for (int i = 0; i < PartCount; i++)
	{
		std::cout << std::setw(15) << part_num[i] << std::setw(35) << desc[i] << std::setw(15) << "$" << price[i] << std::endl;
	}

	return 0;
}


Line 27 would work better using "std::getline()" for the input. And you will need to put this std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // <--- Requires header file <limits>. between lines 23 and 24 for the "std::getline" to work.

After I just played with the "setw()"s until I liked the output. If you do not tell the output to use '-'s the default is space.

Hope that helps,

Andy
Topic archived. No new replies allowed.