I usually don't get stuck on these type of exercises but I didn't really understand how to go forward and backwards with numbers.
3 3 ( The first 3 is how many lines in a for(), the second one is the current channel)
5
7 (5,7,2 are the channels It needs to get trough.
2
Answers:
9 (How many channels it went trough)
DDDDKKKKK (D - up, K - down)
(code)
using namespace std;
//---------------------------------------
void howmany ( int n, int bkan, int &a );
int main ()
{
int n, bkan, a, k;
ifstream df ("TV.txt");
df >> n >> bkan; // 3 3
for ( int i = 0; i < n; i++)
{
df >> a; // 5 7 2
}
cout << k; // how many times
return 0;
}
void howmany ( int n, int bkan, int &a )
{
int k = 0;
for ( int i = 0; i < n; i++)
{
if ( bkan < a ) cout << "D" << endl;
else ( bkan <= a) cout << "K" << endl;
k++;
}
}
}
(/code)
If I have 3 then, it checks if its lower than 5 and it prints out D. But how can I make it that it would remember the letters and move on to the next number?
Any help would be appreciated.
We haven't gotten learning strings yet but it asks us to do it with a void() function.
So I don't really know how to do strings but I know what they do in some way.