Okay, I want to help you, but first I want to ask you something, did your teacher taught you about array ?
if yes then you should try experiment with array, you will recognize that using array will make this problem a joke..
In case that your teacher have taught it in your class but because your absent you did not know about it, I give you this code, but you should study it, it's not that hard..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#include <iostream>
using namespace std;
int main()
{
int i;
int iNumber[] = {1,1,1,2,2,3}; // declare array iNumber [] and store the data of (i)
int jNumber[] = {2,3,4,3,4,4}; // declare array jNumber [] and store the data of (j)
for(i = 0; i <5; ++i) // This for loop only used as a guide to display which data within responsible array
{
cout << "i = " << iNumber[i] << " j = " << jNumber[i] << endl; // print the data stored in respective array
}
return 0;
}
|
The 'for loop' above has nothing to do with the value of i, actually you even don't have to make 2 'for loop' for i and j (I know you make that loop to change the value of i and j, am I right ? But in my code above it has nothing to do with that). Usually 'for loop' is not for changing a value of a data, it's simply used to guide which element of array that would be displayed or something similar like that(but it's not impossible the 'for loop' is used to change the value of a data like you did, but it's rare, at least for me.)
Okay hope this help you. Keep smile
If I did something wrong please forgive me, I just want to help, and I'm sorry.. thanks
P.S. : you can try to change variable i inside the'for loop' above with a or b, and then do the same with the i inside cout command (i.e you change it for (
a=0;
a<5;
a++) then change here to : cout << "i = " << iNumber[
a] << " j = " << jNumber[
a]
How does it ? don't forget change the declaration of int i into int a