Question

In: Computer Science

I did the previous steps and now im at 6 and 7. I can not figure...

I did the previous steps and now im at 6 and 7. I can not figure it out. It is a calculator code, and this part we need to make it password protected. The user is asked to enter in a username and password, and if the password is the backwards of the username you get into the calulator code (that i already have finished below). Use strings and arrays to hold the username and password (maybe use something like gets() and fgets()) and use a do while loop to reverse the password and use strcmp() to compair the two words, if they are the same the calculator will unlock showing my calculator menu, else something like "invalid password" appears on the screen, and asking the user if they desire to try again. Use <stdio.h> and <string.h>

6. Now I want to make sure that nobody uses my calculator without authorization. So a user will have to enter a username and password, which if correct will show the welcome page and menu to the user else it will print the message like “Incorrect password. Authorization denied”. The correct password will be the reverse of the username. So after the user enters the username and password, you will check if the reverse of the password is the username. You will use a while loop to reverse your password. And you will you strcmp() to compare the username the user entered to the reverse of the password.

7. Below are the snapshots of the desired output screen. Figure 1: The above shows the program asking for username and password. We have entered a name in the username and the reverse of that name as the password. Figure 2: If the logging is successful you should print a message “Successful login” and then the menu should be displayed.

#include<stdio.h>


int main() {

   char c;

do {
       printf("Welcome to my calculator\nPlease look at the menu below for your calculations\n");
       printf("1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n5. Modulus \n6. Factorial \n");
       int n, x, y, f, i;
       unsigned long long a = 1;
       printf("Please press your choice from 1-6: ");
       scanf_s("%d", &n);
       getchar();
       switch (n) {
       case 1:
           printf("Enter first number: ");
           scanf_s("%d", &x);
           getchar();
           printf("Enter second number: ");
           scanf_s("%d", &y);
           getchar();
           printf("%d + %d = %d \n", x, y, x + y);
           break;
       case 2:
           printf("Enter first number: ");
           scanf_s("%d", &x);
           getchar();
           printf("Enter second number: ");
           scanf_s("%d", &y);
           getchar();
           printf("%d - %d = %d \n", x, y, x - y);
           break;
       case 3:
           printf("Enter first number: ");
           scanf_s("%d", &x);
           getchar();
           printf("Enter second number: ");
           scanf_s("%d", &y);
           getchar();
           printf("%d * %d = %d \n", x, y, x*y);
           break;
       case 4:
           printf("Enter first number: ");
           scanf_s("%d", &x);
           getchar();
           printf("Enter second number: ");
           scanf_s("%d", &y);
           getchar();
           if (y == 0) {
               printf("Division by 0 is not allowed\n");
           }
           else {
               printf("%d / %d = %d \n", x, y, x / y);
           }
           break;
       case 5:
           printf("Enter first number: ");
           scanf_s("%d", &x);
           getchar();
           printf("Enter second number: ");
           scanf_s("%d", &y);
           getchar();
           if (y == 0) {
               printf("Division by 0 is not allowed\n");
           }
           else {
               printf("The Modulus of %d and %d is: %d \n", x, y, x%y);
           }
           break;
       case 6:
           printf("Enter your number: ");
           scanf_s("%d", &f);
           getchar();
           if (f < 0)
               printf("Error! Factorial of a negative number does not exist\n");
           else {
               for (i = 1; i <= f; i++) {
                   a *= i;
               }
               printf("Factorial of %d = \n", f, a);
           }

           break;
       default:
           printf("Error!! Enter a valid option 1-6\n");

       }
       printf("Do you want to Continue? (Y/N): ");
       scanf_s(" %c", &c);
       getchar();
   } while (c != 'N');
   return 0;
}

Solutions

Expert Solution

#include <stdio.h>
#include <string.h>

//Function definition
char* reverse(char uname[]);

int main() {
   //Declaring character arrays
   char uname[100],pwd[100];
  
   //declaring variable
char c;
  
//getting the firstname entered by the user
printf("Enter Username :");
gets(uname);//inputs value to array
  
    //Getting the password entered by the user
    printf("Enter Password :");
gets(pwd);//inputs value to array
  
//calling the function by passing the string as argument
reverse(uname);

if(strcmp(uname,pwd) == 0 )
{
do {
   printf("Successful login\n");
  
printf("\nWelcome to my calculator\nPlease look at the menu below for your calculations\n");
printf("1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n5. Modulus \n6. Factorial \n");
int n, x, y, f, i;
unsigned long long a = 1;
printf("Please press your choice from 1-6: ");
scanf_s("%d", &n);
getchar();
switch (n) {
case 1:
printf("Enter first number: ");
scanf_s("%d", &x);
getchar();
printf("Enter second number: ");
scanf_s("%d", &y);
getchar();
printf("%d + %d = %d \n", x, y, x + y);
break;
case 2:
printf("Enter first number: ");
scanf_s("%d", &x);
getchar();
printf("Enter second number: ");
scanf_s("%d", &y);
getchar();
printf("%d - %d = %d \n", x, y, x - y);
break;
case 3:
printf("Enter first number: ");
scanf_s("%d", &x);
getchar();
printf("Enter second number: ");
scanf_s("%d", &y);
getchar();
printf("%d * %d = %d \n", x, y, x*y);
break;
case 4:
printf("Enter first number: ");
scanf_s("%d", &x);
getchar();
printf("Enter second number: ");
scanf_s("%d", &y);
getchar();
if (y == 0) {
printf("Division by 0 is not allowed\n");
}
else {
printf("%d / %d = %d \n", x, y, x / y);
}
break;
case 5:
printf("Enter first number: ");
scanf_s("%d", &x);
getchar();
printf("Enter second number: ");
scanf_s("%d", &y);
getchar();
if (y == 0) {
printf("Division by 0 is not allowed\n");
}
else {
printf("The Modulus of %d and %d is: %d \n", x, y, x%y);
}
break;
case 6:
printf("Enter your number: ");
scanf_s("%d", &f);
getchar();
if (f < 0)
printf("Error! Factorial of a negative number does not exist\n");
else {
for (i = 1; i <= f; i++) {
a *= i;
}
printf("Factorial of %d = %li\n", f, a);
}
break;
default:
printf("Error!! Enter a valid option 1-6\n");

}
printf("Do you want to Continue? (Y/N): ");
scanf_s(" %c", &c);
getchar();
} while (c != 'N');   
   }
   else
   {
      printf("**Incorrect password. Authorization denied**\n");
   }
  
  
  

return 0;
}
//function which reverses the character array
char* reverse(char uname[])
{
int m = 0, n= 0,temp;
//Assigning length of the string minus 1 to the variable n
n = strlen(uname) - 1;

//This loop will reverse the string
while (m < n)
{
temp = uname[m];
uname[m] = uname[n];
uname[n] = temp;
m++;
n--;
}
return uname;

}

______________________

output:

_________Thank You


Related Solutions

Im trying to figure out how to draw this Now, in the innermost circle (0.1 m...
Im trying to figure out how to draw this Now, in the innermost circle (0.1 m radius), assume we found 8 species of plant. In the second smallest circle, we found 10 species. In the third smallest circle, we found 13 species. In the largest circle, we found 14 species. Note that when moving from the smallest circle to the next-smallest circle, we did NOT find 10 additional species...The 10 species in the second smallest circle includes the 8 found...
9.) Now, you can also check the calculation you did in #7, by typing the following...
9.) Now, you can also check the calculation you did in #7, by typing the following command: "BINOM.DIST(2,3,.25,1)", which means you want to get two correct (# of successes) out of three items (# of trials), where the probability of getting one item correct is .25 (probability of a success), and we are adding up the probabilities for all values below 2 as well (the cumulative spot is turned on when you type "1"). What is the difference between a...
3, 7, 8, 5, 6, 4, 9, 10, 7, 8, 6, 5 Using the previous question...
3, 7, 8, 5, 6, 4, 9, 10, 7, 8, 6, 5 Using the previous question 's scores, If three points were added to every score in this distribution, what would be the new mean? If three points were added to every score in this distribution, what would be the new standard deviation. Remember, you have already calculated population standard deviation in a previous problem. This problem requires two answers.
So I did the Milestone 1 already and it seems to be correct. But now i...
So I did the Milestone 1 already and it seems to be correct. But now i need to do the Milestone 2 Please help. Street Sweep MILESTONE 1 - Variable & Fixed Cost Exercise INSTRUCTIONS: Determine the per unit cost for each dog. Fill in the blanks to get the per unit cost and fixed cost of each service. Based on 5 grooms per day GROOMING Item Variable Costs Item Fixed Costs Shampoo $                      1.04 Groomer $              2,080.01 Clipper(s)                          ...
I am getting 7 errors can someone fix and explain what I did wrong. My code...
I am getting 7 errors can someone fix and explain what I did wrong. My code is at the bottom. Welcome to the DeVry Bank Automated Teller Machine Check balance Make withdrawal Make deposit View account information View statement View bank information Exit          The result of choosing #1 will be the following:           Current balance is: $2439.45     The result of choosing #2 will be the following:           How much would you like to withdraw? $200.50      The...
Hi so I did a case on Kernicterus and now I have to explain why these...
Hi so I did a case on Kernicterus and now I have to explain why these differential diagnosis are wrong. Below are the differential diagnosis that I have to explain why it isnt kernicterus. Liver disease Hemolytic anemia (baby Acute bilirubin encephalopathy Rh incompatibility Hyperbilirubinemia Nonalcoholic fatty liver disease Biliary Atresia. Thank you for your help.
Chemistry question: We did an experiment in lab and I need to figure out how to...
Chemistry question: We did an experiment in lab and I need to figure out how to A) calculate the mols of NaOH used in titration B) calculate mols HCl in titration C) calculate mols of CaCO3 reacted D) calculate grams of CaCO3 reacted E) calculate percentage of CaCO3 in TUMS. I really need to see all the steps that way I can understand what is going on. We did four titrations with the following information 38 mL HCl, 19.913 g...
Can I determine the steps for an individualized plan of care? Can I determine the importance...
Can I determine the steps for an individualized plan of care? Can I determine the importance of culture in my nursing practice? How can we as nurses maintain good outcomes such as early discharge for your patients? Can I determine the importance and examples of collaborative practice model? Can I define Maslow’s Hierarchy of Needs concepts? And the meaning Can I define jurisdiction for my nursing practice? Scope of practice Can I determine the importance of my patient’s culture when...
To evaluate a firm’s accounting ability can conduct by 6 steps. Explain those steps!
To evaluate a firm’s accounting ability can conduct by 6 steps. Explain those steps!
Please, read the code below so you can figure out what is the steps that are...
Please, read the code below so you can figure out what is the steps that are used. (Answer in words) import java.util.*; import java.io.*; / class WordHelper{ public static String vowels = "aeiouyAEIOUY";    //method to check whether a given character is vowel or not public static String[] sortByVowels(String[] words){ Integer[] noOfVowels = new Integer[words.length]; String[] newArray = new String[words.length];    newArray[i] = words[i]; int cnt = 0; for(int j = 0; j < words[i].length(); j++){ String temp = Character.toString(words[i].charAt(j));...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT