Beginner Programming Homework

Hi there, I'm currently taking a beginners C++ course in college, and we were just assigned our first programming assignment. The problem is, my professor never actually explained how to put together a program and only talked about basic definitions. I'm supposed to write a program that computes tax and and possible totals with different tips on a restaurant bill when the meal total is entered. The tax should be 6.75% of the meal cost and the tips should be 10, 15, and 20 percent of the total after adding tax. I need to display the meal cost, tax amount, tip, and total bill on the screen.

I also need to write a program that asks for 5 test scores, then calculates the average and displays it.

I really have no idea how to write this program except for the most basic structure. Can someone please help get me started or give me an outline of what I'm supposed to write?
First step is to understand the problem. Have you learned about pseudocode? It could help you to break the problem down into small parts by using the human language.

Pseudocode is a cross between human language and a programming language. Although
the computer can’t understand pseudocode, programmers often find it helpful to write an
algorithm in a language that’s “almost” a programming language, but still very similar
to natural language. For example, here is pseudocode for program:

"Design, write and compile, and execute a C++ program that calculates and displays
the amount of money, A, available in N years when an initial deposit of X dollars
is deposited in a bank account paying an annual interest rate of R percent. Use
the relationship that A = X(1.0 + R/100)N. The program should prompt the user to
enter appropriate values and use cin statements to accept the data. Use statements
such as Enter the amount of the initial deposit in constructing your prompts."

Declare the variables
- A = amount of money
- N = number of years
- X = initial deposit
- R = interest rate
Ask the user for the number of years
Input the number of years
Ask the user for the initial deposit
Input the initial deposit
Ask the user for the interest rate.
Input the interest rate
Compute the amount of money (variable A) by using the formula A = X(1.0 + R/100)^N

Notice the pseudocode contains statements that look more like commands than the
English statements that describe the algorithm. The pseudocode even names variables and describes mathematical operations.
closed account (48T7M4Gy)
write a program that computes tax and possible totals with different tips on a restaurant bill when the meal total is entered. The tax should be 6.75% of the meal cost and the tips should be 10, 15, and 20 percent of the total after adding tax. I need to display the meal cost, tax amount, tip, and total bill on the screen.


Preparation
Inputs: Cost
Outputs: Tax, Total, Tips

Rules: Tax is 6.75% of Cost, Tips 10, 15 0r 20% of Total

Pseudocode
Set variables
Get values
Calculate tax
Add to meal cost
Calculate tips for various rates
Calculate totals and display results

Then take that and ...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>

using namespace std;

int main()
{
    
//Preparation
//Inputs: Cost
//Outputs: Tax, Total, Tips
//Rules: Tax is 6.75% of Cost, Tips  10, 15 0r 20% of Total

//Pseudocode
//Set variables
    double cost = 0;
    double tax = 0;
    double total = 0;
    
    double tips_10 = 0;
    double tips_15 = 0;
    double tips_20 = 0;
    
//Get values from user
    cout << "Please enter cost of meal: $";
    cin >> cost;
    
//Calculate tax
    tax = 6.75/100 * cost;
    
//Add to meal cost
    total = cost + tax;
    
//Calculate tips for various rates
    tips_10 = .10 * total;
    tips_15 = .15 * total;
    tips_20 = .20 * total;
    
//Calculate totals and display results
    cout << "Cost plus tax plus 10% tips $" << total + tips_10 << endl;
    //etc etc you can do the rest, making sure money is displayed correctly :)
    
    return 0;
}
Please enter cost of meal: $20.00
Cost plus tax plus 10% tips $23.485
Program ended with exit code: 0
Last edited on
Topic archived. No new replies allowed.