C++ :: Calculating Interest And Making Nested Loops Not Working
Feb 4, 2013
For each quarter, calculate and display the beginning principal balance, the interest earned, and the final principal balance for the quarter.For example: The user entered 1000.00 for the beginning principal balance, 5.25 for the interest rate, and 8 for the number of quarters. The output from this part of the program should be similar to the following:
Q| Beginning Principle| Interest Earned| End Principle
1| $1,000.00 | $13.13 | $1,013.13
2| $1,013.13 | $13.30 | $1,026.42
3| $1,026.42 | $13.47 | $1,039.89
etc
Here is the code I have so far, and I just am not quite sure where to go next.
Code:
{
cout << "Quarters" << " " << "Beginning Principles" << " " <<"Interest Earned" << " " <<"End Principal" << endl;
endprin = balance + (quarter * interest);
interest = quarter * interest;
cout << endprin << endl;
}
View 2 Replies
ADVERTISEMENT
Oct 21, 2014
This exercise should familiarise you with loops, if-then-else statements, and recursion. You will have to design and implement a program that calculates the interest earned on a bank-account. Deadline is the end of Tuesday in week 4.
Interests are compounded; that is, you earn interest on interest. Given a yearly interest rate of say, 6%, you can calculate the total sum available when an initial sum of 4000 pounds is put away for 13 years as follows:
4000 * ( (1 + [6/100])^13 ) = 8531.71 pounds
where the caret symbol denotes 'to the power of'. One way to calculate the power is by repeatedly mulitplying. Ie, you can mulitply 1.06 with 1.06 12 times to calculate 1.06^13.
PART 1
Design and implement a function that raises X to the power Y for a real number X and a positive integer Y. The function must use a while loop.
Design and implement a main program that calculates the sum availble when 1000 pounds has been put away for 25 years with 5 percent interest.
Change the while-loop in the function to a for-loop.
View 12 Replies
View Related
Jun 1, 2013
What output would you expect from this program?" The output was not what I expected. I've psuedo-coded this out and I'm still missing something.
Code:
#include <stdio.h>
int main () {
int numbers[10] = { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int i, j;
}
[code]....
The output: Code: 1 1 2 4 8 16 32 64 128 256 So when I look at this first loop I see that j = 0, which is less than 10, so then the program statement should commence, which is another for loop. So in this inner for loop I see that i = 0, which is not less than j, so this loop should terminate. Then the value of j increments by 1 and the first go around of the loop has completed.
Now I see that j = 1, so this is less than 10, and the inner for loop commences once again. This time though, i actually is less than j, so numbers[1] = numbers[1] + numbers [0], or numbers[1] = 0 + 1. Now the value of i is incremented by 1 and the first go around of this inner loop has completed. Then the value of j increments by 1 and another go around of that loop has completed.
So now j = 2, i = 1, and numbers[2] ( which is 0 ) = numbers[2] + numbers[1], or numbers[2] = 0 + 1. I was expecting the output to be an array full of 1's. However this is not the case..
View 6 Replies
View Related
Dec 7, 2013
Howi can made nested loops?
Code:
for (yax=0; yax<10; yax=yax+1) {
for (xax=0; xax<100; xax=xax+1) {
printf("%d
",yax);
}
}
way what i tired dont work. or maybe works but why this prints only zeros ?
View 8 Replies
View Related
Sep 27, 2014
So in class our teacher assigned us a program where we have to use nested for loops to creates triangles. How does the 2nd for loop print more than 1 star? since the for loop will only run the cout 1 time until it gets to the escape sequence, how does it print more than 1 star on a line? this is what is confusing me. I feel like if i can grasp the understanding of that and what the for loops are doing i can finish the rest of this program with ease
#include<iostream>
using namespace std;
int main()
[Code].....
View 1 Replies
View Related
Jul 11, 2013
Getting close but I think I am stuck on the second loop. The input you put in will be doubled (and it's not supposed to).
Code:
int main() {
int n, i, j, k;
printf("What would you like the height to be? (Positive odd integer)
");
scanf("%d", &n);
[Code] .....
View 3 Replies
View Related
Oct 6, 2013
The user will enter the number of '*'s on the 1st row (ntop) and then the number of rows forming the trapezoid (nrows). (using <iostream>, cout)
For instance, an inverted trapezoid with 7 '*"s in the 1st row and 3 rows forming the inverted trapezoid looks like:
1*******
2 *****
3 ***
(this pyramid is centered, in case it isnt when its posted). Also, each descending row has two less asteriks than the above row.
I am having trouble with the four loop displaying the number of "*" and " ". I know its a relationship with variables in the for loops, my output is just never doing what i want it to.
THis is the guideline for the for loop:
Use for loops to display the inverted trapezoid. Your outer for loop will iterate the total number of rows times. For each row use one nested for loop to display blanks (the 1st row contains no blanks) and another nested for loop to display the characters '*'.
Heres my for loops so far:
for (i = nrows; i >= 1; i--) {
for (j = 0; j >= nrows; j++) {
cout << " ";
} for (k=ntop; k >= 2; k--) {
cout << "*";
} }
The ouput is just blank as of now.
View 2 Replies
View Related
Sep 24, 2013
The output should be something like:
5
45
543
5432
54321
View 2 Replies
View Related
Mar 9, 2013
Write a program that prints a multiplication table using nested loops. In main ask the user for the smallest column number , the largest column number and the size of the increment. Ask the user for the same information for the row values.
In the example the column values entered are: 5, 15 and 2 and the row values 3, 6 and 1.
Given those numbers you would generate the following table.
Multiplication Table
| 5 7 9 11 13 15 ___|___________________________________ | 3 |
15 21 27 33 39 45 4 | 20 28 36 44 52 60 5 | 25 35 45 55 65 75 6 | 30 42 54 66 78 90
Print the 24 values with the grey background. The other numbers show the values to be multiplied.
Code:
#include<stdio.h>
main() {
int a,b,c,d,e,f;
int i,j,total;
printf("Please enter smallest column number: ");
scanf("%i",&a);
printf("
[Code] ....
Challenge:
As an added challenge try to print out the column
headings (5 7 9 11 13 15) and the row headings (3 4 5 6)
View 1 Replies
View Related
Jun 1, 2014
This is a test program that takes a number of arguments from the command prompt and concatenates them into a string object. I was looking into the possibility of using the range-based for loop for this purpose. Can it be done with pointer based arrays? I am mainly doing this because I want to have a firm understanding of range-based for, but also would like to do this with least amount of code possible.
This is my working program:
#include <string>
#include <iostream>
int main(int argc, char *argv[]) {
if (argc > 1) {
std::string concatenatedArgs;
[Code] ....
Can I somehow replace my while-loop with a range-based for? I tried the following but the compiler points out that begin and end were not declared in the scope of the range-based for loop.
#include <string>
#include <iostream>
int main(int argc, char *argv[]) {
if (argc > 1) {
std::string concatenatedArgs;
[Code] ....
View 3 Replies
View Related
Oct 20, 2013
As the title says im trying to make a self balancing robot.
I am using an accelerometer and a gyro as sensors.
I am just really confused when it comes to programming in a PID loop to actually use feedback from the sensors to control the motors.
I sort of understand what needs to be done concering PID loops, just i dont know how to do it.
View 9 Replies
View Related
Nov 8, 2014
Have an assignment due in a few weeks and I'm 99% happy with it My question is is there a method or process for reducing redundant code in nested loops. Ie my code compiles and runs as expected for a period of time and after a few goes it omits a part or prints an unexpected out ext so basically how to find when the redundancy occurs with out posting my code so I can learn for my self?
View 3 Replies
View Related
Oct 28, 2014
I have an assignment for class .. It works, the do-while loop isn't working correctly. Once I am doing inputting information for any employee It should ask to continue. It doesn't, It skips that loop and prompts to enter the type of employee again.
#include <iostream>
#include <iomanip>
using namespace std;
int main( ) {
char empInput;
char continueResponse;
[code].....
View 3 Replies
View Related
Apr 3, 2014
I wrote this code, and everything was working well, but part of the assignment is that it must include nested loops. Once I added the nested while loop, which is basically an if statement, my life was ruined. I am trying to nest a loop in the code that will basically tell the compiler that if the value "loopVol" were to exceed the value of "final" after adding an increment, to run the program for the "final". How can I do that?
Example:
initial = 10
final = 123
increment = 10
as of now, the program would stop at 120, but I want to nest a loop that will tell the compiler to calculate at the final if this happens.
#include <iostream>
#include <iomanip>
#include <stdio.h>
[Code]......
View 3 Replies
View Related
Jun 21, 2013
Equation for compound interest. The interest is supposed to be $43.34 according to the book, I am ending up with around $35. The actual equation is amount = principal * (1 + rate/t)^t where t = number of times compounded per year. I still have to go through and clean up all the code I just want the formula working first.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main () {
float princ, rate, comp, savings, interest, rates, year;
[Code] .....
View 2 Replies
View Related
Jun 7, 2013
I am making this program for a class and it works fine except for the daily interest rate for the checking account is off. The daily interest for the savings computes perfectly. The monthly interest rate for savings is 6% and for checking 3%.
Account.h
#ifndef ACCOUNT_H
#define ACCOUNT_H
#include <iostream>
#include <string>
using namespace std;
const int DAYS_PER_MONTH = 30;
[Code] ....
View 1 Replies
View Related
Sep 24, 2014
Im having problems coding this
A = P(1 + r/n)nt
//Declared test cases
float principal = 200000.00, annualInt = 0.03;
float years = 10.0;
float calcInterest1(float principal, float years, float annualInt) {
float interest1;
float nt = annualInt*12;
float A = principal+annualInt;//Accrued Amount
interest1 = (A = (principal*(1+years/100))pow(nt));// A = P(1 + r/n)nt
return interest1;
}
View 1 Replies
View Related
Jan 17, 2013
I was trying to make a program of calculating simple intrest using functions. I don't know whats wrong with the program but it always shows a wrong output.
#include<iostream.h>
#include<conio.h>
float si(int p,int r,int t) {
return ((p*t*r)/100.0);
[Code] ....
View 4 Replies
View Related
Feb 11, 2014
math part.
The equation I need to use is: payment = [(rate * (1 + rate)^number payments ) / ((1 + rate)^number of payments -1)] * loan
Also, the value of rate in the above equation is (interest/12)/100. So 12% annual interest would be 1% monthly interest.
heres my code:
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
[Code].....
View 4 Replies
View Related
Sep 27, 2013
Here is my code:
int main (int argc, char* argv[]) {
int x = atoi (argv[1]);
int y = atoi (argv[2]);
int z = atoi (argv[3]);
if (strcmp(argv[4], "Simple") == 0){
[Code ....
I need to convert the output of simple interest to float which is $5184.90 instead of $5180. how to go about it?
View 3 Replies
View Related
Apr 7, 2014
I have a problem requiring me to :
enter loan amount:
Enter interest rate:
Enter length of loan (years)
It wants me to input the minimum amount for the loan, and the minimum interest rate. and then output a table that has 5 loan amounts across the top in $10000 increments and 4 interest rates along the side in .25% increments.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main () {
double loan, interest, length, payment,ti;
//Enter loan price
[Code] .....
View 1 Replies
View Related
Jan 25, 2013
Your objective is to write a program that calculates the simple interest for a given loan amount and duration (in years).
Formula:
Simple interest = loan amount X interest rate X number of years
Assume interest rate is a constant 6% per year.
Specifically, your program will:
1. Output descriptive header
2. Prompt and read any customer’s first name, middle initial, and last name individually
3. Prompt and read the principal/loan amount
4. Prompt and read the duration of the loan in years
5. Calculate the interest
6. Output:
a. Customer full name
b. Principal/loan amount
c. Duration of loan
d. Interest rate
e. Interest on loan
f. Principal and interest due at end of term
OK SO THIS IS MY PROGRAM SO FAR. As you can see i got it all but i am so confused with as to for loan amount and duration of year, if i should use float or double to declare it?
i need to finish this assignment by calculating the simple interest and i dont know how or where to begin.
int main(){
system("color f0");
string firstName;
string middleInitial;
string lastName;
cout<<"Please enter your First Name: ";
[Code]...
View 1 Replies
View Related
Nov 29, 2013
Finally got a programme partially working, why the values are not showing? Is this down to incorrect formula or i havent declared the values etc?
Code:
#include <stdio.h>
#include <math.h>
float timeconstant(float R, float C);
float R;
float C;
float time_c;
[Code] ....
View 2 Replies
View Related
Oct 21, 2013
I've been trying to calculate the Second standard deviation but the average in the second loop isn't calculating correctly which is causing the standard deviation (method 2) to not calculate correctly. I can't find anything wrong.
Code:
#include <iostream>#include <iomanip>
#include <string>
#include <fstream>
#include <cmath>
usingnamespacestd;
int main ()
[Code]...
View 8 Replies
View Related
Mar 14, 2013
Currently I am working on a program where you enter in a date 14 03 2013 (Day, Month, Year) and you get the next day. I seem to be coming stuck with months with less than 31 days, and the whole leap year thing. Here is my code so far.
Code:
#include <stdio.h>
int day, month, year, next_day, next_month, next_year, calculation;
int main() {
printf("Enter a date in the form day/month/year: ");
scanf("%d %d %d", &day, &month, &year);
[Code] .....
View 4 Replies
View Related
Feb 19, 2014
As part of a project i want to display the speed of a small wheel on a 7 segment display. I am using a hall effect sensor to pick up the pulses of the rotation. I am not sure how to write a programe on C to calculate the RPM from this....
View 4 Replies
View Related