please help me how i would write these two programs. im learning c++ and am having difficulties, if anyone can help i will greatly appreciate it.

Write a C++ program that displays the results of the expressions 3.0 *5.0, 7.1 * 8.3 – 2.2, and 3.2 / (6.1 * 5). Display the results of each calculation right aligned rounded to two decimal places similar to what is shown below. Calculate the value of each expression manually to verify that the displayed values are correct. An example of how to display output for the first problem is shown below (note there are three math problems to do – you don’t need to use variables just use literals and expressions):

3.0
* 5.0
------
15.00

.... please dont say we dont want to do your homework. thats not the issue. im not going to learn by not doing anything.

the next one is....

The formula to compute the volume of a square based pyramid is:

Volume of Pyramid = A*h/3

where A is the area of the base of the pyramid and h is the height of the pyramid.

Write a C++ program that asks the user to enter the necessary information about the pyramid (note that the user would not know the area of the base of the pyramid, you need to ask them for the length of one of the sides of the base and then calculate the area of the base). Using the information the user input, calculate the volume of the pyramid. Next display the results (rounded to two decimal places). When you display the results you should display the area of the base of the pyramid, the height of the pyramid, and finally the volume of the pyramid. Make sure and format your output in a reasonable way.

^ i have the coding for this, but it calculates the volume, but it needs to calculate the area first, then the volume. i dont know what to do, my head is going to explode.. have been trying to work on these for over a week, nothing.

Well, I will do a little leap of faith and trust that you actually put some effort into it. Here is a very simple example that contains all that you need to do those two problems:

``````#include <iostream>

using namespace std;

int main() {
double width = …``````

## All 2 Replies

Well, I will do a little leap of faith and trust that you actually put some effort into it. Here is a very simple example that contains all that you need to do those two problems:

``````#include <iostream>

using namespace std;

int main() {
double width = 0;
double length = 0;
cout << "Enter the width of the rectangle:" << endl;
cin >> width; //this takes the user input for the width
cout << "Enter the length of the rectangle:" << endl;
cin >> length; //this takes the user input for the length

double area = width * length;
cout << "The area of the rectangle is "
<< setprecision(2) //this sets two decimal points display
<< area; // this prints the area that was calculated

return 0;
};``````

got the pyramid one too work. now off to the other one. thanks. will keep it posted

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.