Question

In: Computer Science

C++: Write correct C++ code for a nested if-else if-else structure that will output a message...

C++:

Write correct C++ code for a nested if-else if-else structure that will output a message based on the logic below.

A buyer can pay immediately or be billed. If paid immediately, then display "a 5% discount is applied." If billed, then display "a 2% discount is applied" if it is paid in 30 days. If between 30 and 60 days, display "there is no discount." If over 60 days, then display "a 3% surcharge is added to the bill."

You do not need to declare the variables or assign them values; just write the code for the nested if-else structure itself and the cout statements to display the messages only.

Solutions

Expert Solution

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

#include <iostream>

using namespace std;

double processPayment(double total, int action);

int main()

{

double total;

int action;

cout << "Enter total amount to be paid:" << endl;

cin >> total;

cout<<"Enter your action 1. immediately paid 2. Billed and will pay in 30 days 3. Others"<<endl;

cin >> action;

total = processPayment(total, action);

cout <<"Total amount to be paid after applying respective discount :"<<total<<endl;

return 0;

}

double processPayment(double total, int action) {

if(action == 1)

{

total = total - (total * 5.0/100.0);

}

else if(action == 2){

total = total - (total * 2.0/100.0);

}

else

{

total = total + (total * 3.0/100.0);

}

return total;

}

​​​​​​​

Kindly revert for any queries

Thanks.


Related Solutions

With C code Write a switch statement (not a complete program) which prints an appropriate message...
With C code Write a switch statement (not a complete program) which prints an appropriate message for a letter code entered. Use the following messages: If L is entered, output the message "Lakers" If C is entered, output the message "Clippers" If W is entered, output the message "Warriors" If any other character is entered, output the message "invalid code" Make sure to handle the case where the user enters in a small letter. That is, a capital or small...
(17pts)Write, compile, and test a C++ program that uses an if-else structure for problem 3.7 on...
(17pts)Write, compile, and test a C++ program that uses an if-else structure for problem 3.7 on page 108.  Use the format specified earlier (initial block of comments with TCC logo, name, etc) Display instructions so that the user understands the purpose of the program and what to enter. Display the results in increasing (non-decreasing) order. Run the program for the following 6 test cases.Turn in a printout of the program and printouts of the 6 test cases.(The result should...
C++ CODE PLEASE MAKE SURE TO USE STRINGSTREAM AND THAT THE OUTPUT NUMBER ARE CORRECT 1....
C++ CODE PLEASE MAKE SURE TO USE STRINGSTREAM AND THAT THE OUTPUT NUMBER ARE CORRECT 1. You must call all of the defined functions above in your code. You may not change function names, parameters, or return types. 2. You must use a switch statement to check the user's menu option choice. 3. You may create additional functions in addition to the required functions listed above if you would like. 4. If user provides option which is not a choice...
Write out code for a nested if statement that allows a user to enter in a...
Write out code for a nested if statement that allows a user to enter in a product name, store the product into a variable called product name and checks to see if that product exists in your nested if statement. You must include 5 product names to search for. If it is then assign the price of the item to a variable called amount and then print the product name and the cost of the product to the console. If...
Re-write following if-else-if statements as Switch statement. Your final code should result in the same output...
Re-write following if-else-if statements as Switch statement. Your final code should result in the same output as the original code below. if (selection == 10) System.out.println("You selected 10."); else if (selection == 20) System.out.println("You selected 20."); else if (selection == 30) System.out.println("You selected 30."); else if (selection == 40) System.out.println("You selected 40."); else System.out.println("Not good with numbers, eh?"); 2. Write a Constructor for the TrafficLight class that sets stopLight value to “red”, waitLight to “yellow” and goLight to “green”?
Please Write Code in C++ and include the correct #include <header> and not a catchall such...
Please Write Code in C++ and include the correct #include <header> and not a catchall such as bits/stdc: Write a recursive, string-valued function, replace, that accepts a string and returns a new string consisting of the original string with each blank replaced with an asterisk (*) Replacing the blanks in a string involves: Nothing if the string is empty Otherwise: If the first character is not a blank, simply concatenate it with the result of replacing the rest of the...
C++ program. Please explain how the code resulted in the output. The code and output is...
C++ program. Please explain how the code resulted in the output. The code and output is listed below. Code: #include <iostream> #include <string> using namespace std; int f(int& a, int b) {    int tmp = a;    a = b;    if (tmp == 0) { cout << tmp << ' ' << a << ' ' << b << endl; }    b = tmp;    return b;    return a; } int main() {    int a...
JAVA Program 2: In Order Using an IF/ELSE IF/ELSE structure, write a program that will prompt...
JAVA Program 2: In Order Using an IF/ELSE IF/ELSE structure, write a program that will prompt the user for three numbers and displays them in ascending order. First, the program will prompt the user for each of the three numbers. Next, find the smallest value of the three. Then decide which of the other two is the next smallest. Then have the program display the three numbers in ascending order. Be sure to do the following: Determine what the input...
In Java: Write a nested loop that allows the user to continuously enter phrases and output...
In Java: Write a nested loop that allows the user to continuously enter phrases and output underscores for each character of the phrase. End when the user enters "done" (ignoring case). Once you have this completed, modify your code so that if the character is whitespace, you print a space " " instead of an underscore - Hint: use Character.isWhitespace(YOURCHARHERE) //returns a boolean.
Write the code to return the output in Rstudio. What is the code? Code: x <-...
Write the code to return the output in Rstudio. What is the code? Code: x <- c(28, 69, 5, 88, 19, 20) Output must be: [1] 4 2 1 6 5 3
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT