Think about the flow of controll, your code makes no since:
You declare some variables with(this is fine, however it is best to initialize upon declaration i.e. double month1 = 0.0):
int transYear, userName, num; // user Name would usually make people think of a string not really an integer
double month1,month2,month3,month4,month5,month6,month7,m onth8,month9,month10,month11,month12;
double qrt1, qrt2, qrt3, qrt4, qrtAvg, annlSales, annlAvg;
Then you try to set some of them with variables that are useless i.e.(uninitialized/have no usefull values):
qrtAvg = (qrt1+qrt2+qrt3+qrt4)/4; // hear you have junk/4 becuase qrt has no real value
annlSales = (month1+month2+month3+month4+month5+month6+month7+ month8+month9+month10+month11+month12); //same here
annlAvg = (month1+month2+month3+month4+month5+month6+month7+ month8+month9+month10+month11+month12)/12; //dido
Then you have some user i/o (this looks fine,but may be problamatic):
cout << "Enter transaction year: \n" ;
cin >> transYear;
cout << "Enter user name: \n";
cin >> userName; // this line will not cause a compile error how ever when the user tries to input a string(there name) cin will set the fail bit flag and you will have a bad read because you have declared it as integer or it will only read the first character of there name in as an integer, either way i would assume that is not the desired outcome.
cout << "Enter montly sales separated by space: ";
cout << endl;
cin >> month1>> month2>> month3>> month4>> month5>> month6>> month7>> month8>> month9>> month10>> month11>>month12;
Then you try to use variables again that have no reall values:
cout << "Sales per quarter are: \n" << qrt1 << "\n"<< qrt2 <<"\n"<< qrt3 <<"\n"<< qrt4; // sending junk to the std out
cout << endl;
cout << "Average quarterly sales are: \n" << qrtAvg; //same here
cout << endl;
cout << "Total annual sales are: \n" << annlSales; //same here
think about what I am saying here rearrange some stuff get some meaningfull data and you should have everything you need.
|