Plzz help.

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= ;
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.
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..

#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");

}
#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"
use this maybe help you
(value by reference) your x,y change in main scope

1
2
3
4
5
void swap (int & x, int & y){
	int tmp = x;
	x = y;
	y = tmp;
}
Last edited on
Sadegh2007.

That dont work..
#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.
Topic archived. No new replies allowed.