array(1-20)

Aug 25, 2008 at 8:54am
hi there!!i am a beginner in dev c++.would anybody please give me a program which can output numbers 1-20 in 4 rows and 5 columns using for loop,while loop and do-while loop..i have made my own program but the output is not succesful..heres my program:#include <iostream>
using namespace std;
int f_loop(int A);
int w_loop(int B);
int dw_loop(int C);
int main()
{
int a[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
char answer,f,w,d,x,y,z;
cout << "I will output the 20 integers in 4 rows and 5 columns\n";
cout << "Press f for for-loops,w for while-loops and d for do-while loops\n";
cin >> answer;
switch (answer)
{ case 'f':
f_loop(x);
break;
case 'w':
w_loop(y);
break;
case 'd':
dw_loop(z);
break;
default:
cout << "not applicable\n";
break;

}
system("pause");
return 0;
}

int f_loop(int A)
{
int b=5;
int a=1;
for(int a=1;a<=20;a++)
cout <<" "<< a << " ";
if (a=b)
cout << endl;
b=b+5;
}

int w_loop(int B)
{
int b=5;
int a=1;
while(a<=20){
cout << " " << a << " ";
a++;}
if(a=b)
cout << endl;
b=b+5;
}

int dw_loop(int C)
{int a=1;
int b=5;
do {cout << " " << a << " " << endl;
a++;
if (a=b)
cout << endl;
b=b+5;}
while(a<=20);}
......please help me in doing this...tnx!!
Aug 25, 2008 at 5:01pm
if( a=b ) is not the same as if( a==b ), this is the main problem. a=b assigns the value of b to a, so this if statement will ALWAYS be true. a==b will tell you if a is the same value as b, if so, true, otherwise false. So, whenever you want to check if something is equal to something else, you must use ==, not =.
Aug 25, 2008 at 7:49pm
Is it me or are those three functions all the same??
Aug 27, 2008 at 1:57pm
i did it..i put another = sign in every if statement but it does the same way..how can i output 4 rows and 5 columns using for statement,while statement and do-while statement?
Topic archived. No new replies allowed.