1.
Miles per Gallon
Problem Statement:
Write a program that calculates a car’s fuel efficiency in miles per gallon. The program should
prompt the user to enter the number of gallons of gas the car can hold and the number of miles
it can drive on a full tank. It should then display the number of miles that may be driven per
gallon of gas.
# include <iostream>
using namespace std;
int main() {
float gallons, miles, mpg;
cout << "Enter the number of gallons the car can hold: ";
cin >> gallons;
cout << "Enter the number of miles it can be driven on a full tank: ";
cin >> miles;
mpg = miles / gallons;
cout << "Miles per gallon: " << mpg << endl;
return 0;
}
2. Sales Prediction
Problem Statement:
The East Coast division of a company generates 58% of the company’s total sales. Given that the
company’s projected sales this year are $8.6 million, write a program that calculates and
displays how much revenue the East Coast division is expected to generate.
# include <iostream>
using namespace std;
int main() {
double totalSales = 8.6e6; // 8.6 million
double eastCoastPercentage = 0.58;
double eastCoastSales = totalSales * eastCoastPercentage;
cout << "The East Coast division will generate $" << eastCoastSales << endl;
return 0;
}
3. Sales Tax
Problem Statement:
Write a program that calculates the total sales tax on a $95 purchase. Assume the state sales
tax is 4% and the county sales tax is 2%. The program should display the total sales tax amount.
# include <iostream>
using namespace std;
int main() {
double purchaseAmount = 95.0;
double stateTax = 0.04;
double countyTax = 0.02;
double totalTax = purchaseAmount * (stateTax + countyTax);
cout << "Total sales tax on a $" << purchaseAmount << " purchase is $" << totalTax << endl;
return 0;
}
4. Restaurant Bill
Problem Statement:
Write a program that calculates the tax and tip on a restaurant bill. For a meal costing $44.50,
apply a tax rate of 6.75% and a tip rate of 15% on the total amount after tax. The program should
display the meal cost, tax amount, tip amount, and total bill.
# include <iostream>
using namespace std;
int main() {
double mealCharge = 44.50;
double taxRate = 0.0675;
double tipRate = 0.15;
double taxAmount = mealCharge * taxRate;
double totalWithTax = mealCharge + taxAmount;
double tipAmount = totalWithTax * tipRate;
double totalBill = totalWithTax + tipAmount;
cout << "Meal cost: $" << mealCharge << endl;
cout << "Tax amount: $" << taxAmount << endl;
cout << "Tip amount: $" << tipAmount << endl;
cout << "Total bill: $" << totalBill << endl;
return 0;
}
5. Average of Values
Problem Statement:
Write a program that stores the values 28, 32, 37, 24, and 33 in separate variables. It should
calculate and display the average of these values.
# include <iostream>
using namespace std;
int main() {
int val1 = 28, val2 = 32, val3 = 37, val4 = 24, val5 = 33;
double average = (val1 + val2 + val3 + val4 + val5) / 5.0;
cout << "The average of the values is " << average << endl;
return 0;
}
6. Annual Pay
Problem Statement:
An employee is paid every two weeks and earns $2,200 each pay period. In a year, the employee
receives 26 paychecks. Write a program to calculate and display the employee's total annual pay.
# include <iostream>
using namespace std;
int main() {
double payAmount = 2200.0;
int payPeriods = 26;
double annualPay = payAmount * payPeriods;
cout << "The total annual pay is $" << annualPay << endl;
return 0;
}
7. Ocean Levels
Problem Statement:
Assume the ocean’s level is rising at a rate of 1.5 millimeters per year. Write a program that
calculates and displays the estimated ocean levels after 5, 7, and 10 years from now.
# include <iostream>
using namespace std;
int main() {
double riseRate = 1.5;
cout << "In 5 years, ocean level will rise " << riseRate * 5 << " mm." << endl;
cout << "In 7 years, ocean level will rise " << riseRate * 7 << " mm." << endl;
cout << "In 10 years, ocean level will rise " << riseRate * 10 << " mm." << endl;
return 0;
}
8. Total Purchase
Problem Statement:
A customer is purchasing five items from a store. Write a program that prompts the user to enter
the price of each item. The program should then calculate the subtotal, add a 6% sales tax, and
display the subtotal, sales tax, and total purchase amount.
# include <iostream>
using namespace std;
int main() {
double price1, price2, price3, price4, price5;
double salesTaxRate = 0.06;
cout << "Enter the price of 5 items: ";
cin >> price1 >> price2 >> price3 >> price4 >> price5;
double subtotal = price1 + price2 + price3 + price4 + price5;
double salesTax = subtotal * salesTaxRate;
double total = subtotal + salesTax;
cout << "Subtotal: $" << subtotal << endl;
cout << "Sales Tax: $" << salesTax << endl;
cout << "Total: $" << total << endl;
return 0;
}
9. Celsius to Fahrenheit
Problem Statement:
Write a program that converts a temperature from Celsius to Fahrenheit. The program should
prompt the user to enter a temperature in Celsius and then display the temperature converted to
Fahrenheit using the formula:
[ F = \frac{9}{5} \times C + 32 ]
# include <iostream>
using namespace std;
int main() {
double celsius, fahrenheit;
cout << "Enter temperature in Celsius: ";
cin >> celsius;
fahrenheit = (9.0 / 5.0) * celsius + 32;
cout << "Temperature in Fahrenheit: " << fahrenheit << endl;
return 0;
}
10. Circuit Board Price
Problem Statement:
An electronics company sells circuit boards at a 40% profit. Write a program that asks the user
for the retail price of a circuit board and then calculates and displays the amount of profit earned
on that board.
# include <iostream>
using namespace std;
int main() {
double retailPrice;
cout << "Enter the retail price of the circuit board: ";
cin >> retailPrice;
double profit = retailPrice * 0.4;
cout << "The profit on the circuit board is $" << profit << endl;
return 0;
}
11. Personal Information
Problem Statement:
Write a program that displays your name, address (with city, state, and ZIP code), telephone
number, and college major, each on a separate line.
# include <iostream>
using namespace std;
int main() {
cout << "Name: John Doe" << endl;
cout << "Address: 123 Main St, Anytown, State, ZIP" << endl;
cout << "Phone Number: 123-456-7890" << endl;
cout << "College Major: Computer Science" << endl;
return 0;
}
12. Triangle Pattern
Problem Statement:
Write a program that displays the following triangle pattern on the screen:
*
***
*****
*******
# include <iostream>
using namespace std;
int main() {
cout << " * " << endl;
cout << " *** " << endl;
cout << " ***** " << endl;
cout << "*******" << endl;
return 0;
}
13. Diamond Pattern
Problem Statement:
Write a program that displays the following diamond pattern on the screen:
*
***
*****
*******
*****
***
*
# include <iostream>
using namespace std;
int main() {
cout << " * " << endl;
cout << " *** " << endl;
cout << " ***** " << endl;
cout
<< "*******" << endl;
cout << " ***** " << endl;
cout << " *** " << endl;
cout << " * " << endl;
return 0;
}