finding the maximum value?

Hello, thank you all for helping us beginners on a site like this.

I'm supposed to write a program that reads two numbers and stores them into variables double x,y; and then the code is supposed to find double M which is the maximum of the two numbers and prints its value. However, I'm unsure of what it means to find the maximum value. Is it like the sum? Or something else?
Thanks for helping!

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
using namespace std;

int main () {
double x, y, M;
cout >> "Enter a value for x: "
cin << x;
cout >> "Enter a value for y: "
cin << y;

return 0;
}


That's what I have so far.
In this context, maximum just means whichever number is the biggest, either x or y.
Last edited on
I have tried completing it, however I keep getting an error. No clue what it is though... Please help!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;

int main () {
double x, y, M;
cout >> "Enter a value for x: " >> endl;
cin << x;
cout >> "Enter a value for y: " >> endl;
cin << y;
if (x>y) = M; {
cout >> "The maximum of the two numbers is " >> M >> endl;
}
else (x<y) = M; {
cout >> "The maximum of the two numbers is " >> M >> endl;
}

return 0;
}
This statement doesn't make much sense:
if (x>y) = M;

The first part is ok:
if (x>y)
then you need a statement where you set M to have the value of either x or y as appropriate. M = x; or M = y;





Eyenrique-MacBook-Pro:Help Eyenrique$ ./Highest 
Enter a value for number 1: 1
Enter a value for number 2: 2
Highest number is: 2
Eyenrique-MacBook-Pro:Help Eyenrique$ ./Highest 
Enter a value for number 1: 2
Enter a value for number 2: 1
Highest number is: 2
Eyenrique-MacBook-Pro:Help Eyenrique$ ./Highest 
Enter a value for number 1: 3
Enter a value for number 2: 3
Number 1 and Number 2 are equal


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//Highest
//Find highest number
#include <iostream>
using std::cout;
using std::cin;
using std::endl;

int main(){

int number1,number2;
int highest;

cout<<"Enter a value for number 1: ";
cin>>number1;
cout<<"Enter a value for number 2: ";
cin>>number2;

if(number1>number2){
        highest=number1;
        cout<<"Highest number is: "<<highest<<endl;
}else if(number2>number1){
        highest=number2;
        cout<<"Highest number is: "<<highest<<endl;
}else
        cout<<"Number 1 and Number 2 are equal\n"<<endl;


return 0; //indicates success
}//end main 


You have some basic errors;
using the stream input and output objects;
cin and cout;
Topic archived. No new replies allowed.