b. Write a function prototype and a function definition for a function that takes one argument of type double. Your function should return the character value ‘P’ provided its argument is positive and return ‘N’ when the argument is either zero or negative.
c. Explain how the function in ‘b’ above could be used to check the correctness of username and password entered into any system
d. Write the function for ‘C’ above and explain your choice of data type for username and password.
I have been able to get the first one done. help with c and d. would be greatly appreciated
#include <iostream>
using namespace std;
char chris(double x){
if(x>0.00)
return 'P';
else
return 'N';
}
int main()
{
int a;
cout <<"Enter a positive or negative number"<<endl;
cin>>a;
char c= chris(a);
cout<<"The result of the number you entered is "<<c;
return 0;
}
I’ve edited your post for readability. As Jeremy said, when you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.
A small note, 0 is positive, so technically a number is negative if its less than 0. The assignment is being a little incorrect in what it’s asking for : )
I feel like we are missing some context. Are there password requirements mentioned in the assignment?
Then this comes down to some brainstorming and justification as to how you can come up with a username or password requirement that relies upon your check above.
Maybe he wants us to write a separate function that’ll be able to check this “correctness” of a username and password entered into a system. Of which I have absolutely no idea about.