Computer Science Canada Something related to loops i think |
Author: | JR [ Mon Sep 27, 2004 5:18 pm ] | ||
Post subject: | Something related to loops i think | ||
Well i got this assigment which i have a starting rate of $2500 and i need to program to tell me after how many years the rate will be $5000 if theres a 7.5% compuned annualy. Heres what i got for now but it doesnt seem to work...
|
Author: | Tony [ Mon Sep 27, 2004 8:11 pm ] | ||
Post subject: | |||
eh? isn't it something like
solving for x you end up with about 10.25 years |
Author: | wtd [ Mon Sep 27, 2004 8:35 pm ] | ||||||||||||||||||
Post subject: | |||||||||||||||||||
Several notes: Header files
The header "iostream.h" is obsolete.
Is the standard way of doing things. The type of "main"
Indicates that "main" is a procedure with no return value.
Is the proper way of writing this. If "main" returns an int, then the program can return a value indicating whether or not the program executed successfully, or if it failed, how. Declare and initialize your variables together
This just makes your code longer than it has to be.
This is much more concise, and ultimately more readable. Using assignment operators
This is overly lengthy.
This is more concise, and shorter code often leaves less opportunity for mistakes. Use whitespace well Your code is easier to understand if you use space judiciously. For instance, put spaces between most operators and values and variables. Secondly, use tabs to indent your code. This will make it easier to follow the flow of the program. Properly use the std namespace You haven't included "using namespace std;" anywhere in your program, so you'd have to use "std::cout" and "std::cin" instead of "cut" and "cin". Finally, the program cleaned up
|