| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Some help, I need it!
Well, I seem to be struggling with an error i get in the for loop line.
Says: expected ')' before ';', and expected ';' before ')' #include <iostream> #include <cmath> using namespace std; int main() { double p = 10000; double counter1 = 10, counter2 = .01, a; cout << "Rate \t Amount at the end of 10th year" << endl; cout << "==== \t ============================" << endl; for ( counter1 = 10 ; counter1 <= 10 ; counter2 = .01 ; counter2 <= .10 ; counter1++ ; counter2++ ; a = p * pow(( 1 + counter2 ), counter1) ){ cout << counter2 << a; } system("pause"); return 0; } Thanks for the help |
|
#2
|
||||
|
||||
|
The basic structure of a for loop is:
for( <initial statement> ; <loop condition> ; <loop statement> ) Where <initiali statment> is just executed once, usually to initialize the loop variable. <loop condition> is executed each loop to see if execution needs to continue or not. <loop statement> is executed each loop and usually increments the loop variable. Example: for( int i = 0; i < MAX; ++i ) { // code here } You for just contains way too many ';'s
__________________
There is no such thing as C/C++, you either program C or C++ |
|
#3
|
|||
|
|||
|
Hi,
Unlike some seemingly intelligent 'simple' languages, such as LOGO, C and C++ are rather pickey about how you write things. The good thing about c and c++ is that it is a little dunb and thus relays on the programmer to define very clearly what he/she wants and think it out instead of just trying untill it works. The way you use your for loop, micht get interpreted by other languages who realy want it to compile very badly, but, at the same time make any clear standard redundant. The for loop takes only three arguments in a particular order. 1. set a varriable 2. give a run condition 3. modify a varriable You can not shuffle them or add different expressions in between. It is a little unclear to me what your program is realy op to, but my guess is that a final working wersion would be like this: Code:
c++
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double p = 10000;
double counter1 = 10, counter2 = .01, a;
cout << "Rate \t Amount at the end of 10th year" << endl;
cout << "==== \t ============================" << endl;
for ( counter1 = 10 ; counter1 <= 10 ; counter2++){
for(counter2 = 0.01; counter2 <= 0.10; counter1++){
a = p * pow(( 1 + counter2 ), counter1);
cout << counter2 << a;
}
}
system("pause");
return 0;
}
Check a tutorial abour for here: http://www.hitmill.com/programming/cpp/forLoop.htm Good luck with finishing the code! |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Some help, I need it! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|