A student need help on C++ assignment

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){
    return 'P';
    return 'N';

int main()
int a;
cout <<"Enter a positive or negative number"<<endl;
char c= chris(a);
cout<<"The result of the number you entered is "<<c; 

    return 0;

Could you please put ``` on the first lines before and after your entire block of code so I can see the correct formatting?

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.

Note: Backticks are not single quotes.



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?

1 Like

No please. No password requirements were mentioned.

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.

Think about it this way. You have one tool to check usernames and passwords: the function you wrote above. What requirements can you check for?

Maybe number of characters