| thashiznitov (5) | |
|
Idn how to solve some questions. i need to do them in c++ and i have no idea how to do it 1): write program to c++ to read three numbers from keyboard and find the average of the three numbers? 2): write program c++ to read two numbers from keyboard and swap between numbers like x=4; y=6; the result x=6; y=4;? I think that int can do that job. but im not sure. 3): must be the result of positive example: (x+(-y)=z)? with abs ? 4): values for each of : X= ;y= ;z= ; | |
|
|
|
| iHutch105 (1092) | |
|
At least make a start. Have you got code for question one? One thing you'll quickly discover on these forums is that nobody is willing to do your homework for you. | |
|
|
|
| danielmtnz (8) | |
|
So what would you need to do in order for you to have the user input 3 numbers? Also how does one find the average? Same for the second question. How does one ask the user to input two numbers then swap their values? There is a syntax for swapping in C++ but I'm not sure if you've learned it yet. First give it a try and post up the code you have so far.. | |
|
|
|
| thashiznitov (5) | |
|
#include <iostream> #include <cmath> #include <fstream> #include <string> using namespace std; void main () { int x,y,z; x=3; y=6; z; z=3+6; cout << " the result is " << z <<endl; system ("pause"); } | |
|
|
|
| thashiznitov (5) | |
|
#include <iostream> #include <cmath> #include <fstream> #include <string> using namespace std; void main () { int x=3; int y=6; x=y; x=7; cout << "x" << x <<endl; cout << "y" << y <<endl; system ("pause"); } " swap between numbers like x=4; y=6; " << --- Thats how i did it. But idn if that realy is "swap" | |
|
|
|
| Sadegh2007 (7) | |||
|
use this maybe help you (value by reference) your x,y change in main scope
| |||
|
Last edited on
|
|||
| thashiznitov (5) | |
|
Sadegh2007. That dont work.. | |
|
|
|
| thashiznitov (5) | |
|
#include <iostream> #include <fstream> #include <cmath> #include <string> using namespace std; void swap (int & x, int & y) { int tmp = x; x = y; y = tmp; system ("pause"); } It gives 2 errors. | |
|
|
|