Using if and nested if statemet write a code for age program

Assignment Help C/C++ Programming
Reference no: EM132082612

If and Nested If

Ask for a password.

If the password is correct then ask for an age. The correct password is "MontyPython".

If the age is greater than 17 print "Shangri-La welcomes you to your earthly paradise!"

If age is less than or equal to 17 print "Sorry, NO under-aged patrons allowed!"

If the password is wrong print "Invalid password!" and the program exits.

There are 4 single-selection ifs. One tests whether the password is correct. One tests whether the password is incorrect. Two are nested ifs that determine which message to print when age is greater than 17 and which message to print when age is less than or equal to 17.

Use printf() and format specifiers: DemoPrintf.java

Exit the main().

What am I doing wrong? Whenever I run program and type the correct password "MontyPython", I get a "invalid password". I will attatch code.

My code:

import java.util.Scanner;
public class LucioMLE31
{
public static void main(String[] args)
{
String password = "MontyPython";
Scanner input = new Scanner(System.in);
int age = 0;
if (password == "MontyPython")
{
System.out.printf("What is the password:");
password = input.nextLine();

if (password != "MontyPython")
{
System.out.printf("Invalid password");
}
}
password = input.nextLine();
System.out.printf("Enter you age:");
age = input.nextInt();
if (age >= 17)
{
System.out.printf("Shangri-La welcomes you to your earthly paradise!");
//END if age>=17
}

if (age < 17)
{
System.out.printf("Sorry, NO under-aged patrons allowed!");
}//END if age<17
}

Reference no: EM132082612

Questions Cloud

What risks and rewards may emerge from an increase : What risks and rewards may emerge from an increase in the use of the powers of the office?
Determine which customers must be served : Write a program to determine which customers must be served from each field stations.
What are three areas to look to fix this problem : You have a network with a DNS server and a DHCP server on it. Both are running on different servers.
Build an index html html page for your bank web application : Build an "index.html" HTML page for your "Bank" Web Application. This document should say Welcome to "Bank"(or whatever you want to call your Bank).
Using if and nested if statemet write a code for age program : Determine which message to print when age is greater than 17 and which message to print when age is less than or equal to 17.
Research new network observation tools : Research new network observation tools that use enhanced techniques, such as virtual machine-based code execution.
A report on summarizing nessus more important features : Read more about Nessus and write a one page report summarizing its more important features.
Describe how nessu is useful to network security specialist : Write a pragraph describe how it is useful to a network security specialist and how it may be used for harmful purposes by a hacker?
Write a program that reads in a string of numbers : Write a program that: (1) Reads in a string of numbers (2) Loops through the digits in the string (3) For each digit in string print that many '+' on a line.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  What is normalization and what is functional dependency

How does Tuple-oriented relational calculus differ from domain-oriented relational calculus. What is normalization? What is Functional Dependency?

  The "continue" and "break" statements

How are the "continue" and "break" statements different from the "exit" and "return" statements?

  Calculations to assess the performance and position

Use the information from the above calculations to assess the performance and position of the company. State the limitations regarding ratio analysis as a means of analysing company accounts.

  Write a program that reads from a file a list of course name

Write a program that reads from a file a list of course names, letter grades for each course and number of credits each course is worth. The program will read each course name, grade earned and number of credits from the file and print out the course..

  Prepare your own unique while-end repetition structure

Create your own unique While-End repetition structure. You decide the theme. You should provide both the pseudocode and the flowchart of your example.

  Problem regarding the command-line parameter

Your program will deal with three input files: a text file to check (the "user file"), a dictionary file containing correct spellings, and a settings file. The words in the user file will be spell-checked, and any resulting corrections written bac..

  Creating an array of names

Just write the codes and label my variables. Example: (with Python not C++). Creating an array of names

  Identify two key oo concepts and explain them as if you

1. discuss the advantages and disadvantages of both the structured and object-oriented oo paradigm in programming. why

  Write a function that permanently swaps two integers

Write a function that permanently swaps two integers using pointers.

  Creates a bus class

write a program that creates a bus class. create a constructor that initializes the number of passengers and number of seats. declare four objects. use the default copy constructor to initialize two of the objects.

  Application shows a user friendly message

The software fails to respond to user inputs, if there is a connectivity problem with the database. Add the code snippet that the development team should use to ensure that the application shows a user- friendly message, if such a situation arises..

  Write a c program that displays a table showing the price

write a c program that displays a table showing the price of silver and gold. the table will have three columns. the

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd