I am currently taking the "CS50 Introduction To Computer Science" course, and I'm still quite new to programming in C. I'm working on a simple agreement project that involves using if statements. However, as a beginner, I'm facing some difficulties with my code.
If there's anyone experienced with C programming who could lend a helping hand, I would be incredibly grateful for your assistance. Below is the code that I've attempted so far:
#include <stdio.h>
#include <cs50.h>
#include <string.h>
int main(void)
{
string username = get_string("What would you like your username to be? ");
string agreement = get_string("Do you agree to the following terms & conditions? ");
if (!strcmp(agreement, "yes" || agreement, "y" || agreement, "Yes" || agreement, "Y"))
{
printf("You can now continue using the service, %s! \n", username);
}
else if (!strcmp(agreement, "no" || agreement, "n" || agreement, "Yes" || agreement, "Y"))
{
printf("You need to agree to the terms & conditions to use the service\n");
}
else
{
printf("You need to select a option\n");
}
}
And here is the error that is thrown when I try to compile the code:
Too many arguments for function call. Expected 2, Have 5
I tried to search similar questions on google and found this result: How to check if variable equal to multiple values But, I couldn't solve my problem. Here is the code that I tried (which did not work):
#include <stdio.h>
#include <cs50.h>
#include <string.h>
int main(void)
{
string username = get_string("What would you like your username to be? ");
string agreement = get_string("Do you agree to the following terms & conditions? ");
if (str[agreement] == 'yes' || str[agreement] == 'y' || str[agreement] == 'Yes' || str[agreement] == 'Y')
{
printf("You can now continue using the service %s! \n", usename);
}
else if (str[agreement] == 'no' || str[agreement] == 'n' || str[agreement] == 'No' || str[agreement] == 'N')
{
printf("You need to agree to the terms & conditions to use the service\n");
}
else
{
printf("You need to select a option\n");
}
}
But I received this error:
Use of undeclared identifier "str"
I'm excided to learn and appreciate any guidance or tips you can provide to help me make progress on this project. Thank you so much for your time and support!