c= 3 + 10*k - k*k
Here are the two functions:
CrackCypher - this will contain the loop
CheckAnswer - this will check whether the value of k produces a negative value
Make sure that check answer returns a bool value, and takes an integer input.
Crack Cypher should return an integer as well.
You should determine what integer value of k makes the cypher negative.
#include <iostream>
int CrackCypher (int Guess);
bool CheckAsnwer(int c);
usingnamespace std;
int main()
{
int Guess;
CrackCypher(Guess);
}
bool CheckAsnwer(int c)
{
int k;
c = 3 + (10*k) - (k*k);
return c;
}
int CrackCypher (int Guess)
{
for (int k = 0; k < 21; k++)
{
int c;
int CheckAnswer(c);
if (c < 0)
{
cout << c;
}
}
}
I can do this perfectly fine without having to use functions, but since we have to use functions I have problems 'translating' it.
This is the code without using functions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
usingnamespace std;
int main()
{
int c;
for (int k = 0; k < 21; k++)
{
c = 3 + (10*k) - (k*k);
if (c < 0)
{
cout << c;
}
}
}