1.Create a procedure that converts miles to kilometers. Allow the user to choose
ID: 3820074 • Letter: 1
Question
1.Create a procedure that converts miles to kilometers. Allow the user to choose which way to convert: miles to kilometers or kilometers to miles. Have the user input the amount in one unit and then have a message box give the answer in the other unit.
2.Create an error checking procedure that asks the user to enter a six digit number. If the user doesn’t enter six numbers, ask them to reenter until they get it right.
3.Create a program that begins with displaying a random number between 1-10. The user will be prompted to select above, below or same number. The computer will then generate another random value between 1 and 10. If you guessed right you will win. If you lose, it will ask you to play again until you win.
EXCEL VBA
Explanation / Answer
1.Ans:
USE [master]--I am using master database you can use any other database
GO
/****** Object: StoredProcedure [dbo].[sp_MileKMConversion] Script Date: 03/07/2017 23:55:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE Procedure [dbo].[sp_MileKMConversion]( --Schema is dbo
@opt VARCHAR(50),--opt is taking to choose whether to convert KMtoMile or MiletoKM
@val FLOAT)
AS
BEGIN
if(@opt='KMtoMile')
BEGIN
SET @val= @val*1.6093
PRINT @val
END
ELSE IF(@opt='MiletoKM')
BEGIN
SET @val= @val/1.6093
PRINT @val
END
END
GO
2.Ans:
USE [master]--I am using master database you can use any other database too
GO
/*Enter a Number within single Quote
EXEC [dbo].[sp_ErrorCheckingSixDigit] '46658'
*/
/****** Object: StoredProcedure [dbo].[sp_ErrorCheckingSixDigit] Script Date: 03/07/2017 23:52:44 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[sp_ErrorCheckingSixDigit]( --Schema is dbo
@num Varchar(10))--Taking the value
AS
BEGIN
IF(LEN(@num)=6)--checking whether it is 6 digit number or not
BEGIN
PRINT @num --Printing the Number if it is a six digit number
END
ELSE
BEGIN
PRINT 'Enter a valid Six Digit Number'
END
END
GO
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.