#C++ Assignment
130 messages · Page 1 of 1 (latest)
!f
#include <iostream>
using namespace std;
int main() {
// declare variables
int num1, num2, num3, average
// executable statements
// return 0;
}
@grave plaza Do you know how to set variables?
yikes, it seems it doesn't even wants you to set the value of the variables
ah wait it does on one of the images
but yeah a musterkitteh what exactly are you stuck on?
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
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:
- Programiz
- codecademy
- learncpp.com if you have prior experience with programming
- [Programming Challenges](#archived-resources message)
- CodinGame
- LeetCode
- HackerRank
- An Introduction to Modern CMake
- Our #archived-resources channel. It contains many useful utilities.
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
```cpp
int main() {
return 0;
}
```
!f
#include <iostream>
using namespace std;
int main() {
// declare variables
int num1, num2, num3,
average
num1 = 125 num2 = 28 num3 = -25
// executable statements
// return 0;
}
also keep in mind in C++ things are terminated with a ; after statements
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?
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
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
well how is an average normally calculated?
add 3 numbers up / by 3
bingo
well how would you write it in a math function?
125+28+-25
right so now time to translate it into code
it's very similar to what you would do normally
!f must be used while replying to a message
!f
#include <iostream>
using namespace std;
int main() {
// declare variables
int num1, num2, num3, average;
num1 = 125;
num2 = 28;
num3 = -25;
return 0;
}
I would do it after
that yes
the num3
Would I start it by
average =
average = 125+28+-25 / 3
yeah but you would not write the 125 and 28 etc
you would use the variables you made
yeah
hower just like math, order of operation and order is a thing
/ 3 is going to devide only num3 by 3
nope
Assign /3 to each variable
/ has a higher priority then +
technically a possibility but not the correct approach
how would you do this in regular math? ensure lower priority operaions get done first
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
thats why I wrote my code
so (num1 + num2 + num3) / 3
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
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
3 * (3+6) --> 3 * (9) --> 27
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.
okay
How do i fix this
why is it warning me
also thank you for helping me
i really appreciate it
well the next step is propably actually using it
yup
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
#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;
}
just needed some basic math help and some clarity on vocab lol
Thank u so much I appreciate all your help
!solved