Please help me to answer this questions because i need to pass it on monday thankyou.
These are the problems
Repetition Control
1. Develop a program that accumulates the total number of days for years 2000 to 2009. Remember, any year divisible by 4 is a leap year and has 366 days.
2. there are 10,000 people in a town whose population increases by 10% each year. Develop a program that determines how many years it would take for the population to exceed 30,000
3. When robin's baby was born, she opened a savings account with $1,000.00. On each birthday, starting with the first, the bank added an additional 5% of the balance and robin added another $500.00 to the account. Develop a program that will determine how much money was in the account on the child's 18th birthday.
4. Develop a program that continues to read data values as long as they are not decreasing. The program should stop reading whenever a number smaller that the preceding one is entered.
5. A mathematician named Ulam proposed generating a sequence of numbers from any positive integer n(n > 0) as follows:
- If n is 1, stop.
- If n is even, the next number is n/2.
- If n is odd, the next number is 3*n + 1.
- Continue with this process until reaching 1.
Here are some examples for the first few integers.
2 -> 1
2 -> 10 -> 5 -> 16 -> 8-> 4-> 2-> 1
4 -> 2-> 1
5-> 16-> 8-> 4-> 2-> 1
6-> 3-> etc as for 3 above.
7 -> 22 -> 11 -> 34 -> 17 -> 52 -> 26 -> 13 -> 40 -> 20 -> 10 -> 5 -> see 5 above.
Develop a program that will read a value for n and generate the ulam sequence.
hello nico, please show you own efforts so far and where exactly you're getting stuck or explain what specific questions you have about any of the problems
We aren't asking you to solve your own problem, since if you knew how to do that you wouldn't be here asking for help. Instead, we're asking you to show your attempt so that
a.) the problems you present are specific enough for the solutions to be potentially useful to others; and
b.) those who help you don't have to create all the boilerplate for a solution.
If you don't do that you're basically posting a prompt (five prompts, actually) and hoping that someone finds them interesting enough to solve. The first question asks you to create a program which counts the number of days in the years 2000-2009.
@gunnerfunner knows his stuff, so you should probably take his suggestion. It's a good idea.
I have solved your 1st problem. its not ideal, but I think its a start.
I didn't have time to fix problem with array, as you need 10 arrays and I am using 11.
I am sure there is more finest way of dealing with leap year, today I am too tired to think of this. Maybe on Monday how knows ;)
good luck mate.
// 10K people.cpp : Defines the entry point for the console application.
//
//2. there are 10, 000 people in a town whose population increases by 10 % each year.
//Develop a program that determines how many years it would take for
//the population to exceed 30, 000
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
usingnamespace std;
int main()
{
int people = 10000;
int increase = 0;
int yearCount = 1;
while (people < 30000)
{
increase = (people * 0.010);
people = people + increase;
cout << "year " << yearCount++<< ": " << people << endl;
}
system("pause");
return 0;
}
// BabyMoney.cpp : Defines the entry point for the console application.
//3. When robin's baby was born, she opened a savings account with $1,000.00.
//On each birthday, starting with the first, the bank added an additional 5% of
//the balance and robin added another $500.00 to the account. Develop a program
//that will determine how much money was in the account on the child's 18th birthday.
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
usingnamespace std;
int main()
{
float fund = 1000;
int motherDeposti = 0;
float increase = 0;
for (int i = 0; i < 19; i++)
{
increase = fund * 0.05;
fund = fund + increase + motherDeposti;
cout << "Baby savings in year: "<< i << " amount of $" << fund << endl;
motherDeposti = 500;
}
system("pause");
return 0;
}
Nico144
got question about this one:
4. Develop a program that continues to read data values as long as they are not decreasing. The program should stop reading whenever a number smaller that the preceding one is entered.
how do you generate numbers?
by hand?
randomly generated?
from list?
something else?
// Ulam-Sequence.cpp : Defines the entry point for the console application.
//
/*
5. A mathematician named Ulam proposed generating a
sequence of numbers from any positive integer n(n > 0) as follows:
- If n is 1, stop.
- If n is even, the next number is n/2.
- If n is odd, the next number is 3*n + 1.
- Continue with this process until reaching 1.
Here are some examples for the first few integers.
2 -> 1
2 -> 10 -> 5 -> 16 -> 8-> 4-> 2-> 1
4 -> 2-> 1
5-> 16-> 8-> 4-> 2-> 1
6-> 3-> etc as for 3 above.
7 -> 22 -> 11 -> 34 -> 17 -> 52 -> 26 -> 13 -> 40 -> 20 -> 10 -> 5 -> see 5 above.
Develop a program that will read a value for n and generate the ulam sequence
something about Ulam
https://en.wikipedia.org/wiki/Stanislaw_Ulam
*/
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
usingnamespace std;
int main()
{
int inputNumber = 0;
cout << "Please type number: ";
cin >> inputNumber;
for (; inputNumber >= 2;)
{
if (inputNumber % 2 == 0)
{
inputNumber = inputNumber / 2;
cout << inputNumber << " ";
}
else
{
inputNumber = ((inputNumber * 3) + 1);
cout << inputNumber << " ";
}
}
system("pause");
return 0;
}
I recommend taking some lessons on the Web like from code academy or other websites that meant just for that.
It's very important to code without errors as it can save a lot of time for you.
If you are having problems detecting those by yourself you can also try using some program to help you. I tend to use checkamrx and it works fine.
Good luck anyways.
Ben.