# Program to Compare Two Given Strings for Equality

Program to Compare Two Given Strings for Equality in C++,These days kids are introduced to computers at a very early age and in some schools,

# Compare two given Strings for Equality

In this post we will be discuss the Program to Compare Two Given Strings for Equality i.e., to check whether the inputted strings are same or not. Also, the required logic is discussed and the source code is written in C++ which is compiled successfully to provide the best results.

Problem Description

Automated Dictation Evaluation I

These days kids are introduced to computers at a very early age and in some schools, the dictation test is conducted using computers. The teachers found it a bit difficult to evaluate these tests and they requested the school management to lessen their burden by automating this task. The 12th class students are learning C++ programming and they took up the task of automating the dictation evaluation. You need to check if the given string is equal to the correct string to evaluate each student. Can you please help them out? Write a C++ program to compare 2 strings using strcmp() function.

INPUT FORMAT:

Input consists of two strings.

Assume that the maximum length of the string is 50 and it contains only alphabets.

OUTPUT FORMAT:

Refer sample input and output for formatting specifications.

SAMPLE INPUT :

Excellent

Excellent

SAMPLE OUTPUT:

It is correct

Explaination :

In this we will be discussing the Program to Compare Two Given Strings for Equality i.e., to check whether the inputted strings are same or not. This can be done by using the string library module in C++. Therefore we will compare both the strings using the strcmp() function inside a conditional statement and print the required set of results as per the problem need.

Logic to follow to come-up with the solution :

1. Declare the required variables to use in the program and input them.

2. Use the string library module to compare both the inputted strings.

3. Using strcmp() function, if both strings leads to be sane then print the required sets.

4. Otherwise it is concluded that both the strings are different.

Let’s write the required code for the problem :

Code :

```#include<iostream>

#include<string.h>

using namespace std;

int main()

{

char s1[50],s2[50];

cin>>s1>>s2;

if(strcmp(s1,s2)==0)

cout<<"It is correct";

else

cout<<"It is wrong";

return 0;

}
```

Sample Test Cases have been passed successfully

If you liked this post, then share this with your friends and if anything is confusing or incorrect then let me know in the comment section.

Thanks from my side, this is Mayank, keep learning and exploring !!

Mayank Pathak is the editor and blogger at "The Coding Bro".He loves to codes, learn new technologies, and write the coding solutions and articles for the communities of learners, especiall…