Questions on programming

Hi everyone,

I have this question I need to answer, pls

I need to write a program that will do :

1- the program will ask you to enter 2 numbers then it will find the ,aximum.
2- the program will ask you to enter 3 numbers and it will find the average of them.
3- the program will ask you to enter the number of quarters and halfs, then it will calculate the value in cents.

Thank you..
That is not a question...
Anyway, you won't get much help of you don't show your efforts ( ie: some code )
actually that's what I need,

I have basic knowledgement on C++

#include <iostream>
#include <cmath>

int main()
{

}


I just don't know how to write the codes to let do as above..
the program will ask you to enter 2 numbers
Can you do that? if you can't see http://www.cplusplus.com/doc/tutorial/basic_io/
here's what I have come up with

#include <iostream>

using namespace std;
int main()
{
int a, b;

cout<<"Enter First Number: "<<endl;
cin>>a;
cout<<"Enter Second Number: "<<endl;
cin>>b;

if (a>b)
{
cout<<"The Max Integer is: "<<a;
}
else
{
cout<<"The Max Integer is: "<<b;
}

int c, d, e, Avg=0;

cout<<"Enter 3 Numbers"<<endl;
cin>>c>>endl>>d>>endl>>e>>endl;

cout<<Avg;



return 0;
}


can you help me, how to do it..please
The average is equal to the sum of your numbers divided by the number of numbers.
ie: (c+d+e)/3.
Notice the dot after the three makes it a double, without it you would get an integer division.
ok there least I come up with:



#include <iostream>

using namespace std;
int main()
{
int a, b;

cout<<"Enter First Number: "<<endl;
cin>>a;
cout<<"Enter Second Number: "<<endl;
cin>>b;

if (a>b)
{
cout<<"The Max Integer is: "<<a;
}
else
{
cout<<"The Max Integer is: "<<b;
}

int c, d, e, Avg=0;


cout<<"Enter 3 Numbers to find the Average on them"<<endl;
cin>>c>>d>>e;

cout<<"The Average is: "<<Avg=(c+d+e)/3<<endl<<endl;


is that correct? I have a problem, I use 2005 Express Edition which I'm not fully familiar with, when it should print the Avg value it just closes, it doesn't say " press any key to exit"
Here it is, help in correcting wrong lines, please..try and execute it pls


[


#include <iostream>
using namespace std;
int main()
{
int a, b, c, d, e, Avg=0;



cout<<"Enter First Number: ";
cin>>a;
cout<<"Enter Second Number: ";
cin>>b;
cout<<endl;
if (a>b)
{
cout<<"The Max Number is: "<<a<<endl;
}
else
{
cout<<"The Max Number is: "<<b<<endl<<endl;
}

cout<<endl<<endl<<endl;



cout<<"Enter 3 Numbers to find the Average on them"<<endl;
cin>>c>>d>>e;
Avg=(c+d+e)/3;

cout<<"The Average is: "<<Avg<<endl<<endl;


int q, h, cent;

cout<<"Enter Numer of quarters"<<endl;
cin>>q;
cout<<"Enter number of Halfs"<<endl;
cin>>h;

cent=(q*25)+(50*h);

cout<<"The number of Cents is: "<<cent;

return 0;
}

]



I'm on Vista 64 bit
Last edited on
is that correct? I have a problem, I use 2005 Express Edition which I'm not fully familiar with, when it should print the Avg value it just closes, it doesn't say " press any key to exit"
Get a newer version http://www.microsoft.com/express/download/ and read http://www.cplusplus.com/forum/articles/7312/
I think there's another way to get the max integer..

max()

what is the code?
Topic archived. No new replies allowed.