understanding this C++ module?
Given a type Money that is a structured type with two int fields,
dollars and cents. Assume that an array named monthlySales with 12
elements , each of type Money has been declared and initialized .
Assume that a Moneyvariable yearlySales has also been declared . Write
the necessary code that traverses the monthlySalesarray and adds it all
up and stores the resulting total in yearlySales. Be sure make sure that
yearlySales ends up with a valid value , i.e. a value of cents that is
less than 100.
Now i'm not asking for the answer but, i'm asking how do i approach it.
simply because i'm not sure how to address the question like how to code
it. I have understand the first paragraph of the question respectively.
here is my snippet of code. now im just stuck on how to compute it. i just
need a bit of guidance. Thanks! the code i have so far it access the array
i have of 12 elements and assigns them random numbers of dollars and cents
respectively.
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
using namespace std;
struct Money
{
int dollars,cents;
};
int main()
{
Money monthlySales[12], yearlySales;
for (int i = 0; i < 12; i++)
{
monthlySales[i].cents =rand()%99;
monthlySales[i].dollars =rand();
}
return 0;
}
No comments:
Post a Comment