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

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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