This code gives the wrong output, which looks like several times the value of a variable went out of range during filling (although I myself entered units only). Here is the code itself:

#include <iostream> int main(void) { #define MONTHS_IN_YEAR 12 #define YEARS 3 using std::cin; using std::cout; using std::endl; char* months[MONTHS_IN_YEAR] = { "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december" }; int sales[YEARS][MONTHS_IN_YEAR], years[YEARS] = { 2011, 2012, 2013 }, year_sales[YEARS], sum = 0; for (int i = 0; i < MONTHS_IN_YEAR; i++) for (int n = 0; n < YEARS; n++) { cout << "Enter the sales on " << months[i] << " of " << years[n] << ": "; (cin >> sales[n][i]).get(); } for (int i = 0; i < YEARS; i++) for (int n = 0; n < MONTHS_IN_YEAR; n++) year_sales[i] += sales[i][n]; for (int i = 0; i < YEARS; i++) sum += year_sales[i]; for (int i = 0; i < YEARS; i++) cout << "In " << years[i] << " " << year_sales[i] << " copies of the book \"C++ for retards\" were saled" << endl; cout << "Total sales for " << YEARS << " years: " << sum << endl; return 0; } 

Where is the mistake?

    1 answer 1

    You have not initialized the year_sales array, its values ​​are random ...