Question

write a c++ code be sure the user only enter A or a for packageA, B...

write a c++ code be sure the user only enter A or a for packageA, B or b for packageB, C or c for packageC. If the user inputs some other value display an error message saying " invalid out".

When you ask the user to input the number of minute and the user enters a negative value you should display the same error message "invalid input" in both cases, after you display the error

message the program should stop (exit). Please write the logic in c++ I'm writing a program and I want know how to write logic in my code.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program in C++:-

#include<iostream>
using namespace std;

int main()
{
//This menu will show in the beginning of the program.
cout<<"'A' or 'a': For packageA"<<endl;
cout<<"'B' or 'b': For packageB"<<endl;
cout<<"'C' or 'c': For packageC"<<endl;
cout<<endl;
cout<<"Please enter your choice from the above menu: ";
//choice variable take the choice of user on above menu.
char choice;
cin>>choice;
//If A or a selected then it will print "You are in packageA".
if(choice == 'A' || choice == 'a'){
//In this section, you can add your own code that should be run in packageA.
cout<<"You are in packageA"<<endl;
}
//If B or b selected then it will print "You are in packageB".
else if(choice == 'B' || choice == 'b'){
//In this section, you can add your own code that should be run in packageB.
cout<<"You are in packageB"<<endl;
}
//If C or c selected then it will print "You are in packageC".
else if(choice == 'C' || choice == 'c'){
//In this section, you can add your own code that should be run in packageC.
cout<<"You are in packageC"<<endl;
}

//if user enters different character.
else{
cout<<"invalid out"<<endl;
//it will exit from the execution.
exit(0);
}

int minute;
cout<<"Enter the number of minute: ";
cin>>minute;
//when user input negative value of minute variable.
if(minute < 0){
cout<<"invalid input";
//it will exit from the execution.
exit(0);
}

//here, you can add your code after checking the negativity of minute.
return 0;
}

Output:-

When you will choose the wrong choice initially.

When you enter the negative value of minute.

In the above program, I just code as the question says.

Add a comment
Know the answer?
Add Answer to:
write a c++ code be sure the user only enter A or a for packageA, B...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA 2. (8 points) Write a code segment which prompts the user to enter the price...

    JAVA 2. (8 points) Write a code segment which prompts the user to enter the price of a tour and receives input from the user. A valid tour price is between $52.95 and $259.95, inclusive. Your program should continue to repeat until a valid tour price has been entered. If the user enters an invalid price, display a message describing why the input is invalid. You may assume that the user only enters a real number. The user will not...

  • In C++ 1. Write a program that allows a user to enter 10 integer values from...

    In C++ 1. Write a program that allows a user to enter 10 integer values from the keyboard. The values should be stored in an array. 2. The program should then ask the user for a number to search for in the array: The program should use a binary search to determine if the number exists in a list of values that are stored in an array (from Step #1). If the user enters a number that is in the...

  • Write a program that asks the user to type an even number or 111 to stop....

    Write a program that asks the user to type an even number or 111 to stop. When the user types an even number, display the message “Great Work”, and then ask for input again. When the user types an odd number, display the message “Try again” and ask the user to enter again. When the user enters the sentinel value of 111 the program ends I've attempted this but it went horribly wrong. we are only suppose to use while,...

  • You want to write a converter program which will let user convert distance and weight from SI to ...

    Use functions to complete this C + + program You want to write a converter program which will let user convert distance and weight from SI to the USCS system and vice versa The formulae are as follows: 1. Distance in miles- distance in kilometers x 1.60 2. Weight in kilograms weight in pounds x 2.20 The program would let user input the number that they want to convert and then choose the units to and from which they want...

  • Write a code segment that prompts the user to enter a double number between (5.55 and...

    Write a code segment that prompts the user to enter a double number between (5.55 and 123.3) inclusive. If the input is invalid, print an error message and loop until the input is valid. Code in c++

  • write programs with detailed instructions on how to execute. code is java What you need to...

    write programs with detailed instructions on how to execute. code is java What you need to turn in: You will need to include an electronic copy of your report (standalone) and source code (zipped) of your programs. All programming files (source code) must be put in a zipped folder named "labl-name," where "name" is your last name. Submit the zipped folder on the assignment page in Canvas; submit the report separately (not inside the zipped folder) as a Microsoft Word...

  • Write a C# program that prompts a user to enter a birth month and day. Display...

    Write a C# program that prompts a user to enter a birth month and day. Display an error message if the month is invalid (not 1 through 12) or the day is invalid for the month (for example, not between 1 and 31 for January or between 1 and 29 for February). If the month and day are valid, display them with a message.

  • Write a program which: - prompts the user for 2 numerical inputs - stores their two...

    Write a program which: - prompts the user for 2 numerical inputs - stores their two inputs in variables as floats - Use a while in loop to ask a user for a valid operation: (if the user's input operation isn't one of those listed above, instead print a message telling them so, and continue asking for the valid operation) - prompts the user for an arithmetic operation ( + - * / %) - stores the user's input as...

  • You are to write a program IN C++ that asks the user to enter an item's...

    You are to write a program IN C++ that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: if the an item's wholesale cost is 5.00 and its markup percentage is 100%, then the item's retail price is 10.00 If an item's wholesale cost is 5.00 and its markup percentage is 50%, then the item's retail price is 7.50 Program design specs. You should have 5...

  • Has to be written in C++ Write a program that asks the user to enter the...

    Has to be written in C++ Write a program that asks the user to enter the month (1-12) and the year (0-2019). Validate the input and print an error and stop the program if an invalid month or year was entered. The program should then display the number of days in that month. Use the following criteria to identify leap years: Determine whether the year is divisible by 100. If it is, then it is a leap year if and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT