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>
usingnamespace 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;
}
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>
usingnamespace 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;
}
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
//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;
}elseif(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;