#C++ Assignment

130 messages · Page 1 of 1 (latest)

grave plaza
#

I am not sure where to go from here, im new at coding and trying to get the basics down

hard wasp
#

!f

twin roverBOT
#
#include <iostream>

using namespace std;

int main() {
  // declare variables
  int num1, num2, num3, average

  // executable statements

  // return 0;
}
Munsterkitteh
hard wasp
#

@grave plaza Do you know how to set variables?

maiden comet
#

ah wait it does on one of the images

#

but yeah a musterkitteh what exactly are you stuck on?

grave plaza
#

I dont know what to type after declaring my variables

#

im trying to

#

Write C++ statements that store 125 into num1, 28 into num2, and –25 into num3.

#

Like so im trying to store the numbers in the system

#

and I forgot how to do that

maiden comet
#

right, then one step at the time

#

lets begin with storing 125 in num1.

twin roverBOT
#
How to Learn C++ Programming

Everyone learns differently, but the best way is to learn by doing:
Working on personal projects, solving programming challenges, etc.
Here are some resources to accompany you:

C++ Tutorials
Practice
See Also
grave plaza
#

So I would write

#

num1 = 125

#

?

#

or do i have to write int num1;

#

before that

#

So, I have this now

#

How do i format this right

twin roverBOT
#

```cpp
int main() {
return 0;
}
```

maiden comet
#

!f

twin roverBOT
#
#include <iostream>

using namespace std;

int main() {
  // declare variables
  int num1, num2, num3,
      average

          num1 = 125 num2 = 28 num3 = -25

  // executable statements

  // return 0;
}
Munsterkitteh
maiden comet
#

also keep in mind in C++ things are terminated with a ; after statements

grave plaza
#

What statement would I put the ; after

#

Ok well first what are statements

#

and the next thing its asking is

#

Write a C++ statement that stores the average of num1, num2, and num3 into average.

#

so would I write num1, num2, num3 = average?

maiden comet
#

well ; marks the end of the statement

#

in the example I send on how to initialize variables there is a good few examples on where to put the semicolons as well

#

but honestly if this kind of stuff is unclear I might surgest a different learning source 😅

#

this is like bare bare basics of C++ that any tutorial should convey well

grave plaza
#

yes i know Im reading through the link you sent me its my first week in this class im taking for computer programming and were just now touching on basics of coding

#

we had learned input/output devices, secondary storage cpu, mm, ram , etc

#

we havent really touched on variables etc

#

just this week we have and all she did was make a video on a few programming examples but Im still trying to get grip on it

#

How do I store the average of num1, num2, num3 into average

maiden comet
#

well how is an average normally calculated?

grave plaza
#

add 3 numbers up / by 3

maiden comet
#

bingo

grave plaza
#

How do i write that

#

into a code

maiden comet
#

well how would you write it in a math function?

grave plaza
#

125+28+-25

maiden comet
#

right

#

and to average it?

grave plaza
#

divide the number i gte by 3

#

get*

#

which is 42.6666667

maiden comet
#

right so now time to translate it into code

#

it's very similar to what you would do normally

grave plaza
#

ok so

#

!f

twin roverBOT
grave plaza
#

!f

twin roverBOT
#
#include <iostream>

using namespace std;

int main() {
  // declare variables
  int num1, num2, num3, average;

  num1 = 125;
  num2 = 28;
  num3 = -25;

  return 0;
}
Munsterkitteh
grave plaza
#

I would do it after

#

that yes

#

the num3

#

Would I start it by

#

average =

#

average = 125+28+-25 / 3

maiden comet
#

yeah but you would not write the 125 and 28 etc

#

you would use the variables you made

grave plaza
#

num1, num2, num3?

#

average = num1 + num2 + num3 / 3;

maiden comet
#

yeah

#

hower just like math, order of operation and order is a thing

#

/ 3 is going to devide only num3 by 3

grave plaza
#

so it would need to be

#

backwards?

maiden comet
#

nope

grave plaza
#

Assign /3 to each variable

maiden comet
#

/ has a higher priority then +

maiden comet
#

how would you do this in regular math? ensure lower priority operaions get done first

grave plaza
#

pemdas

#

Im not that great at math

#

I am thinking though

#

well ok i thought that I add all the numbers up

#

then divide that number by 3

maiden comet
#

that could work yeah

#

you can also simply wrap them addition in ()

grave plaza
#

thats why I wrote my code

maiden comet
#

so (num1 + num2 + num3) / 3

grave plaza
#

OOOOO

#

So group them together

#

So its like when you

#

have

#

3(3+6)=

#

u like mulitply the 3 by 3

#

and 3 by 6

#

orrrr am i wrong lol

#

like the outside to the inside

maiden comet
#

well yeah thats a thing but a simpler thing in this case with c++ is just doing the things in the () first and then the thing outside

#

so it becomes 3 x 9

grave plaza
#

ok im lost

#

again

maiden comet
#

3 * (3+6) --> 3 * (9) --> 27

grave plaza
#

oh

#

ok

#

Ok i have this

#

but its saying the error on the right

#

Write C++ statement(s) that output the values of num1, num2, num3, and average.

maiden comet
#

it's a warning not an error

#

it's saying average is never used what it isn't

grave plaza
#

okay

#

How do i fix this

#

why is it warning me

#

also thank you for helping me

#

i really appreciate it

maiden comet
#

well the next step is propably actually using it

grave plaza
#

So i need to output the values

#

cout?

maiden comet
#

yup

grave plaza
#

cout << "num 1 =" << num1 endl;

#

oops

#

cout << "num 1 =" << num1 << endl;

#

and so fourth with the other num and then average

#

ayyyyy I did it

#

!f

twin roverBOT
#
#include <iostream>

using namespace std;

int main() {
  // declare variables
  int num1, num2, num3, average;

  num1 = 125;
  num2 = 28;
  num3 = -25;

  average = (num1 + num2 + num3) / 3;

  cout << "num 1 =" << num1 << endl;
  cout << "num 2 =" << num2 << endl;
  cout << "num 3 =" << num3 << endl;
  cout << "average =" << average << endl;

  return 0;
}
Munsterkitteh
grave plaza
#

just needed some basic math help and some clarity on vocab lol

grave plaza
#

!solved