How to create this program

This is my first semester of college and I got put into "Intro to Programming Principles using C++". and.... I have no idea whatsoever what is going on in this class. I try to understand but I am no good with computers/math and putting the two together is a disaster. I have a homework assignment due tomorrow, which I tried to figure out but it all just goes over my head. ANY help to this problem is appreciated, I really don't want to get a 0 on this..

For each of the following, write the C++ statement to perform the operation. Then create a C++ program that incorporates these statements. Run the program using 45 as the input and hand in both the program and the output. Make sure the program is documented appropriately, follows the program criteria for the course and is easy to read.

-Declare the variables x, y, and z as double.
-Declare the variables i, and j as integers and initialize both to 0 within the declaration statment.
-Write an assignment statement to give the value 4.56 to y
-Write an assignment statement to give the value 0.1 to x
-Print the message "Enter an integer"
-Receive a value from the user for i
-Add x and i and store the result in y
-Add x and i and store the result in j
-Print the message "Y is: " immediately followed by the value for y
-On a new line, print the message "J is: " immediately followed by the value for j
-On a new line, print the message "Z is: " immediately followed by the value for z
-Set z's value to be j's value.
-Multiply the value in x by 5 (storing the result in z)
-Multiply the quantity (y+y/6) with z (store the result in z)
-Print the message "X is: " immediately followed by the value for X. (Note: NO new line)
-On a new line, print the message "Y is: " followed by a tab and then the value for Y
-On the same line as the previous output, print the message "Z is: " followed by two tabs and then the value for Z
-Print two blank lines and then the message "I is: " followed by a space and then the value for i
-On the same line as i's value, print the message "J is: " followed by a new line and then the value for J
-Print two blank lines followed by your name
Did you try opening the textbook?
The good news is these instructions are very crystal clear.

I would start reading the tutorial on this site, ASAP:
http://www.cplusplus.com/doc/tutorial/

(Read everything in the section "Basics of C++")
yeah i read the book, which also went over my head. I have no experience with any of this and even after being in this class for two weeks, I still do not even understand what these codes are supposed to do. I've even researched this stuff and I don't get it. It might sound stupid, but it makes no sense to me. and my teacher started teaching like we were all experienced.

and thanks, Ill try that.
Let's try taking this from the start, can you declare a variable?
if the firsts need to be declared as doubles, would it just be

#include <iostream>
using namespace std;

int main()
{
double x;

or double x=0.1; ??


double x;

This is just a declaration.

double x=0.1;

This is a declaration and an assignment.

Notice how in the assignment, declaring and assigning x is split into two parts:

-Declare the variables x, y, and z as double.
...
-Write an assignment statement to give the value 0.1 to x
ok, thanks. so more like this:


#include <iostream>
using namespace std;

int main()
{
double x;
double y;
double z; ?

and then to declare i and j can I just keep going but with "int" instead of "double". and I'm not sure what it means to initialize in this case, I guessed it would just be
int i=0;
int j=0;
but that might just be an assignment statement, unless it means the same thing? I'm sorry, I'm really trying to understand this.
1
2
3
double x;
double y;
double z;

That's correct. Step 1 complete!

1
2
int i=0;
int j=0;

Correct as well. Initialization means giving the variable its first value. In this case, the initialization (which is really just an assignment) and declaration are happening at the same time. Note that this is good programming practice. At this point the variables x, y, and z are uninitialized (the assignment requires this).
ok thanks so much. you and the url above is helping all this become a little more understandable.

hannjo wrote:
For each of the following, write the C++ statement to perform the operation.
...
-Declare the variables x, y, and z as double.
-Declare the variables i, and j as integers and initialize both to 0 within the declaration statment.

Not sure if the professor cares about semantics, but you can do this in a more compact way, using exactly one C++ statements for each given instruction as follows:
1
2
double x, y, z; //"Declare the variables x, y, and z as double."
int i = j = 0; //"Declare the variables i, and j as integers and initialize both to 0 within the declaration [statement]." 
Note that for line 2 you could have also written int i = 0, j = 0; //a single C++ statement but I read "within the declaration statement" (not statements) as meaning one compound assignment.
Last edited on
Topic archived. No new replies allowed.