Concept explainers
The following statements use conditional expressions. Rewrite each with an if /else statement.
A) j = k > 90 ? 57 : 12;
B) factor = x >= 10 ? y * 22 : y * 35;
C) total += count == 1 ? sales : count * sales;
D) cout << (((num % 2) == 0) ? "Even\n" : "odd\n");
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Starting Out with C++ from Control Structures to Objects (8th Edition)
Additional Engineering Textbook Solutions
Java How To Program (Early Objects)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Starting Out with Java: From Control Structures through Objects (6th Edition)
Modern Database Management (12th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
- The company discounted used cars pays their employees according to this chart: 250$ per months plus 50$ per car sold. If the salesman sells more than 10 cars, the employee receives a bonus of 5% of the total of his sales, in addition to his regular salary.Each month, the owner sits in front of the computer, and enters the following information: The name of the employee, the number of cars sold, as well as the total of all the sales for the month. algorithm that will calculate the salary of an employee for the month, and then display on the screen, his name, total cars sold, base salary, bonus if applicable and entire salaryarrow_forwardsoftware.cpp A software company sells a package that retails for $99. Quantity discounts are given according to the following table. Quantity 10-19 20-49 50-99 100 or more Discount 20% 30% 40% 50% Write a program that asks for teday's date (you MUST use cin >> date. Do not use getline(cin, date), the company name and the quantity'they wish to buy and computes the total cost of the purchase. If the user enters a negative value for the quantity, tell him/her "invalid quantity". If a zero is entered, tell "Hope you decide to buy our software in the future." Otherwise display an invoice in the same format shown below. Your prompts and outputs have to look exactly the same as the following sample run (spacing too). I used 30 spaces for the labels and 10 spaces for the numbers. [kslotteempress cs111_lec_fall16]s ./a.out Enter today's date (mm/dd/yy): 09/27/16 Enter your company name: Little Coffee Shop Enter the quantity you would like to purchase: 10 Invoice for Little Coffee Shop Price…arrow_forwardLIFE INSURANCE PREMIUM CALCULATOR Write a C program that calculates monthly, quarterly, half-yearly and yearly life insurance premium based on given sum assured. Monthly Premium Quarterly Premium Half Yearly Premium Yearly Premium sum assured / (years*12). sum assured / (years*4). = sum assured / (years 2). = sum assured / years. %3D %3D Output of program Enter your sum assured: 250000 Enter life insurance policy term (in years):5 Your Monthly Premium Your Quarterly Premium Your Half Yearly Premium: 25000.00 Your Yearly Premium : 4166.67 : 12500.00 : 50000.00arrow_forward
- 35. Evaluate: 1+6==7 || 3+2==1. Write T for true and F for false ( ||-or)arrow_forwardTransaction solution for Joe's Pizza, your friendly neighborhood pizza shop.Joe wants to record each transaction through the day and get the sum at the end of day. He would like to enter a transaction value into the program. Then he will let computer know there are more transactions to come by typing in Y. At the end of day, he will type a N and computer program should give him a sum of sales and exit. Please help him with this request. can you plz make it util.scanner form and can you make it so i can copy and past it plz thank you in advancearrow_forward// Program prompts users for names and quantities for a $2.00 product abd displays total for each user until "XXXXX" is entered Declarations string name num quantity num PRICE_EACH = 2.00 num total start string PROMPT1= "Enter name string PROMPT2 = "Enter quantity" string QUIT = "XXX" string END_MSG = "End of job" housekeep() stop name → QUIT? endOfJob() No endOfJob() stop output END_MSG Yes detailLoop() housekeeping() output PROMPT1 input name return detailLoop() output PROMPT2 input quantity total = quantity* PRICE_EACH output name, total output PROMPT1 returnarrow_forward
- You may only use 'not' and 'or' to solve this along with parenthesesarrow_forwardRewrite the following statement with an if/else statement: total += count = = 1? sales : count * sales;arrow_forwardUntitled Section This is a segment of program, when it executed with multiple values for n and s the program displays the value of f, choose which output of f values are wrong answers cin>>x>>y; if (x>1) &&(y<5) {f=x+y*9; else f-x-y-11; } cout<arrow_forwardif s=15; t=-6; r=0; u=9; how will evaluate s > t && r < uarrow_forwardProblem: Feed Nibble Monster Till Full Write a program that generates a number in [0, 500] at the beginning -- this corresponds to how hungry the monster is -- and keeps asking the user to feed the monster until that number falls to zero. Each time the user feeds the monster a nibble, hunger decreases by the decimal value of the character (i.e. if the user feeds 'A' hunger decreases by 65). But when the user feeds the monster some character that isn't a nibble, the hunger increases by the decimal value of the character (since puking depletes energy). Use while loop. Sample runs: Notice the loop exits after one iteration, because hunger was very low and one nibble made the monster full: Notice hunger increasing after non-nibble (pink highlight): Notice that the program just keeps going when the user feeds the monster only non-nibbles. Do you think the program will keep running forever if the user never gives the monster nibbles?arrow_forwardC++ Mobile Service ProviderModify the program in Problem 5 so that it also displays how much package A customers would save if they purchased package B or C, and how much money Package B customers would save if they purchases Package C. If there would be no savings, no message should be printed. calculate the cost of all plans (A, B, and C) based on the number of minutes the user-entered. Then based on the plan user chose, compare, and calc. the difference among the plans.arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr