#include <iomanip>
#include <fstream>
#include <iostream>
usingnamespace std;
void Skaityti (int & n, int V[]);
void Spausdinti (int n, int V[]);
int main()
{
setlocale (LC_ALL, "Lithuanian");
int n;
int V[100];
Skaityti (n, V);
Spausdinti (n, V);
return 0;
}
void Skaityti (int & n, int V[])
{
ifstream fd ("varles.txt");
fd >> n;
for (int i=0; i < n; i++)
{
}
}
void Spausdinti (int n, int V[])
{
int p;
int t;
int h;
int m;
int k=1;
int k1=1;
for (int j=0; j < n-1; j++)
{
for (int i=j+1; i < n; i++)
if (V[j] > V[i])
{
V[i] += k1++;
}
if (V[i] != V[j])
{
V[j] += k++;
}
}
cout << k << " " << k1;
}
#include <iomanip>
#include <fstream>
#include <iostream>
usingnamespace std;
void Skaityti (int & n, int V[]);
void Spausdinti (int n, int V[]);
int main()
{
setlocale (LC_ALL, "Lithuanian");
int n;
int V[100];
Skaityti (n, V);
Spausdinti (n, V);
return 0;
}
void Skaityti (int & n, int V[])
{
ifstream fd ("varles.txt");
fd >> n;
for (int i = 0; i < n; i++)
{
}
}
void Spausdinti (int n, int V[])
{
int p;
int t;
int h;
int m;
int k = 1;
int k1 = 1;
for (int j = 0; j < n - 1; j++)
{
for (int i = j + 1; i < n; i++) // See note below.
if (V[j] > V[i])
{
V[i] += k1++;
}
if (V[i] != V[j]) // This statement is not part of the for() statement directly above so i is not defined.
{
V[j] += k++;
}
}
cout << k << " " << k1;
}
Note: Remember that without braces only one line is included in the body of a control statement.
Your indentation is not the most informative. Lets try:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
for ( int j=0; j < n-1; j++ )
{
for ( int i=j+1; i < n; i++ )
{
if (V[j] > V[i])
{
V[i] += k1++;
}
} // scope of i ends here. Been so for years.
if (V[i] != V[j])
{
V[j] += k++;
}
}
for (int i=j+1; i < n; i++)
if (V[j] > V[i])
{
V[i] += k1++;
}
if (V[i] != V[j])
{
V[j] += k++;
}
I'm not sure what's going on with that indentation, but I believe it's confusing you as well as me.
Your for loop (line 34) has no { curly braces } after it, so only the if-statement on line 35 is within the for loop.
Perhaps you meant something like this?
(not tested)
1 2 3 4 5 6 7 8 9 10 11
for (int i=j+1; i < n; i++)
{
if (V[j] > V[i])
{
V[i] += k1++;
}
if (V[i] != V[j])
{
V[j] += k++;
}
}