The code below is a program to input and print a number of books sold for three years. I'm not able to print the sum of books sold for each year, but I can print the total number of books sold for the 3years. I'm a beginner. I need help to enable continue my reading.
I will appreciate if you can throw more lights on array that could be or help.
Thanks
#include <iostream>
#include <string>
int main()
{
using namespace std;
int counter1 = 2000;
int SumSold[3][12];
int NumSold[3];
string months[3][12] =
{
Re: loop and array problem for beginner. Please HELP!
You need to initialize your numeric arrays to contain 0s. You seem to be assuming they will for now, but that's not guaranteed. Just adding "= {0};" after the declaration should do it.
Re: loop and array problem for beginner. Please HELP!
You mean sum up the values in the array? You could use std::accumulate, but for a beginner it's probably best to just use a loop. That's what accumulate() is doing internally anyway.
Re: loop and array problem for beginner. Please HELP!
Im just interested to know why you used "endl" twice in the 'number of books sold from 2001-2003 bit, or is that just a mistake. Sorry Im a total noob at C++.
Bookmarks