Thursday
April 24, 2014

Homework Help: computer science

Posted by Cheryl on Friday, February 24, 2012 at 5:37pm.

my code works in c++ so the logical I am getting error must be in the reading of the problem, but I can't see it:

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 Money variable yearlySales has also been declared. Write the necessary code that traverses the monthlySales array 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.

Money monthlySales[12];
yearlySales.cents = 0;
yearlySales.dollars = 0;

for(int j = 0; j < 12; j++)
{
cin >> monthlySales[j].dollars;
cin >> monthlySales[j].cents;
}

for(int i = 0; i < 12; i++)
{
yearlySales.cents = yearlySales.cents + monthlySales[i].cents;

yearlySales.dollars = yearlySales.dollars + monthlySales[i].dollars;

}
while(yearlySales.cents > 100)
{
yearlySales.cents -= 100;
yearlySales.dollars += 1;
}

Answer this Question

First Name:
School Subject:
Answer:

Related Questions

computer science - ineed help with c++. i am using code blocks and i have a ...
Computer Programming - Can anyone give me a site that contains a C source code. ...
ICT - i have been given a question to give an explanation of what logical ...
probability - out of 250 students interviewed at a community college, 90 were ...
computer program - where can i find a computer code for Simpson's 1/3 Rule using...
biology - 1.explain how the code that is found in the organism`s genes works 2....
Computer Information - A __________ provides the tools that a programmer uses to...
Computer Science - Hi can you guys help me with these output code, I think you ...
computer - What does tenure track, part time instructor of computer science does...
computer science - I need help with c++ on the codeblocks. when i run the ...

Search
Members