Answer to Question #185050 in C for jack

Question #185050

1.Ask user to enter three words. You can assume that each word has the maximum 

length of five characters. 


2. Combine the three words to form a passphrase. For example, if the user enters the 

words “I”, “love” and “you”, the passphrase should be “Iloveyou”. 


3. Ask user to enter a passphrase. Check whether the passphrase entered by the user is 

the same as the passphrase generated in Step 2 above. If the passphrase entered is 

the same, prints out “Passphrase is correct!”. Otherwise, prints out “Wrong 

passphrase!”. 


1
Expert's answer
2021-04-24T11:19:36-0400
#include <stdio.h>
#include <string.h>

int main()
{
    char word1[5];
	char word2[5];
	char word3[5];
	char passphrase[15];
    //get the first word from the user
	printf("Enter the first word: ");
    scanf("%s",word1);
	//get the second word from the user
	printf("Enter the second word: ");
    scanf("%s",word2);
	//get the third word from the user
	printf("Enter the third word: ");
    scanf("%s",word3);
	//Combine the three words to form a passphrase.
	strcat(word1,word2);
	strcat(word1,word3);
	
	// Ask user to enter a passphrase. 
	printf("Enter a passphrase: ");
    scanf("%s",passphrase);
	// Check whether the passphrase entered by the user is 
	//the same as the passphrase generated
	if(strcmp(word1,passphrase)==0){
		 //If the passphrase entered is the same, prints out "Passphrase is correct!". 
		 printf("Passphrase is correct!\n\n");		
	}else{
		//Otherwise, prints out "Wrong passphrase!"
		printf("Wrong passphrase!\n\n");		
	}


	getchar();
	getchar();
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS