Reputation: 41
I have good experience in Python and very little in C++. I'm trying to write a program to print each element of the 'sales' array:
#include <iostream>
#include <iomanip>
using namespace std;
void printArray(int, int);
int main()
{
char chips[5][50] = {"mild", "medium", "sweet", "hot", "zesty"};
int sales[5][6] = {0};
int tempSales, counter;
const int i = 5;
for (counter = 0; counter < i; counter++)
{
cout << "Please enter in the sales for " << chips[counter] << ": ";
cin >> tempSales;
tempSales >> sales[counter][5];
}
cout << "{";
for (int counter = 0; counter < i; counter++)
{
cout << chips[counter] << ", ";
}
cout << "}" << endl;
cout << "{";
for (int counter = 0; counter < i; counter++)
{
cout << sales[counter] << ", ";
}
cout << "}" << endl;
return 0;
}
To solve this problem, I need to have the same commands and keywords I still have, and it can't be any advanced or weird syntax. What's going on? I'm getting results like:
{mild, medium, sweet, hot, zesty, }
{010FF6F4, 010FF70C, 010FF724, 010FF73C, 010FF754, }
Whereas I just want to see 1, 2, 3, 4, and 5 for the second array. Please help!
Upvotes: 1
Views: 87
Reputation: 350
Also the assignment into chips and sales won't repeat the initialization pattern.
Upvotes: 1
Reputation: 448
You are using a two dimensional array with sales[][]
but then try to read from it like from a one dimensional one. Instead just declare it with int sales[5]{}
and save your input with
tempSales >> sales[counter];
Upvotes: 1