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.
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;
computer science - MathMate, Saturday, February 25, 2012 at 7:38am
Here's a little detail:
while(yearlySales.cents ≥ 100)
Can you post your Money class, data and output?
computer science - MathMate, Saturday, February 25, 2012 at 8:37am
You also missed out
Otherwise it should work as expected.
computer science - Cheryl, Saturday, February 25, 2012 at 9:03pm
myprogramming lab- the bane of my existance- code works in c++ but not in myprogramminglab so I wondered if I was missing something in the question
computer science - MathMate, Saturday, February 25, 2012 at 9:30pm
Sorry, can't help much there. Don't have access to myprogramminglab.
But double-checking with a real programming language is the way to go.
Answer This Question
More Related Questions
- computer science - Assume that BlogComment is a structured type with these ...
- itcs 1140 - Homework # 4 ~ Strategic Planning for Wy’East Coffee solve it on ...
- statistics - The power of a significance test for a particular value of the ...
- computer science - What is a type of operator that uses the AND, OR, and NOT? I'...
- math-Statistics - I have been working on the Type I error and a Type II error ...
- mathematics - seeds of type A and type B are sold in packets, each must contain ...
- Statistics - A test is made of H0: mean = 27 versus H1: mean < 27. The true ...
- math - In printing an article of 21,000 words, a printer decides to use two ...
- computer science - Algorithm for Binomial Numbers Task Binomial numbers (or ...
- computer programming - Construct a structure chart, as well as a flowchart and ...