0% found this document useful (0 votes)
27 views

Assignment

The document contains C++ source code for two programs that take in 5 numbers as input and output the highest or second highest number. The first program outputs the single highest number among the 5 inputs. The second program enhances this by outputting the second highest number. Both programs use a series of if-else statements to compare the numbers and determine the highest or second highest value.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Assignment

The document contains C++ source code for two programs that take in 5 numbers as input and output the highest or second highest number. The first program outputs the single highest number among the 5 inputs. The second program enhances this by outputting the second highest number. Both programs use a series of if-else statements to compare the numbers and determine the highest or second highest value.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Bantola, Ferl-Ann A.

Eng124

12/15/12

Mr.Bernie Fabito

1.)
Source Code
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

//Assign6.2
#include <iostream>
using namespace std;
int main(){
int num1,num2,num3,num4,num5;
cout<<"Enter 5 numbers = "<<endl;
cin>>num1>>num2>>num3>>num4>>num5;
if (num1>=num2&&num1>=num3&&num1>=num4&&num1>=num5)
cout<<"The Higest is "<<num1<<endl;
else if (num2>=num1&&num2>=num3&&num2>=num4&&num2>=num5)
cout<<"The Higest is "<<num2<<endl;
else if (num3>=num1&&num3>=num1&&num3>=num4&&num3>=num5)
cout<<"The Higest is "<<num3<<endl;
else if (num4>=num1&&num4>=num2&&num4>=num3&&num4>=num5)
cout<<"The Higest is "<<num4<<endl;
else if (num5>=num1&&num5>=num2&&num5>=num3&&num5>=num4)
cout<<"The Higest is "<<num5<<endl;
system("pause");
return 0;
}

2.)
Sample Dialogue:
Enter 5 numbers =
4
13
11
19
8
The Second Highest is 13

Assign62.cpp

Bantola, Ferl-Ann A.

Eng124

12/15/12

Source Code
//Assign6.3
#include <iostream>
using namespace std;
int main(){
int num1,num2,num3,num4,num5;
cout<<"Enter 5 numbers = "<<endl;
cin>>num1>>num2>>num3>>num4>>num5;
{
if (num1>=num2&&num1>=num3&&num1>=num4&&num1>=num5)
{
if (num2>=num3&&num2>num4&&num2>num5)
cout<<"The Second Highest is "<<num2<<endl;
else if (num3>=num2&&num3>num4&&num3>num5)
cout<<"The Second Highest is "<<num3<<endl;
else if (num4>=num2&&num4>num3&&num4>num5)
cout<<"The Second Highest is "<<num4<<endl;
else if (num5>=num2&&num5>num3&&num5>num4)
cout<<"The Second Highest is "<<num3<<endl;
}
else if (num2>=num1&&num2>=num3&&num2>=num4&&num2>=num5)
{
if (num1>=num3&&num1>num4&&num1>num5)
cout<<"The Second Highest is "<<num1<<endl;
else if (num3>=num1&&num3>num4&&num3>num5)
cout<<"The Second Highest is "<<num3<<endl;
else if (num4>=num1&&num4>num3&&num4>num5)
cout<<"The Second Highest is "<<num4<<endl;
else if (num5>=num1&&num5>num3&&num5>num4)
cout<<"The Second Highest is "<<num5<<endl;
}
else if (num3>=num1&&num3>=num1&&num3>=num4&&num3>=num5)
{
if (num1>=num2&&num1>num4&&num1>num5)
cout<<"The Second Highest is "<<num1<<endl;
else if (num2>=num1&&num2>num4&&num2>num5)
cout<<"The Second Highest is "<<num2<<endl;
else if (num4>=num1&&num4>num2&&num4>num5)
cout<<"The Second Highest is "<<num4<<endl;
else if (num5>=num1&&num5>num2&&num5>num4)
cout<<"The Second Highest is "<<num5<<endl;
}
else if (num4>=num1&&num4>=num2&&num4>=num3&&num4>=num5)
{
if (num1>=num2&&num1>num3&&num1>num5)
cout<<"The Second Highest is "<<num1<<endl;

Mr.Bernie Fabito
Assign63.cpp

Bantola, Ferl-Ann A.

Eng124

12/15/12

else if (num2>=num1&&num2>num3&&num2>num5)
cout<<"The Second Highest is "<<num2<<endl;
else if (num3>=num1&&num3>num2&&num3>num5)
cout<<"The Second Highest is "<<num3<<endl;
else if (num5>=num1&&num5>num2&&num5>num3)
cout<<"The Second Highest is "<<num5<<endl;
}
else if (num5>=num1&&num5>=num2&&num5>=num3&&num5>=num4)
{
if (num1>=num2&&num1>num3&&num1>num4)
cout<<"The Second Highest is "<<num1<<endl;
else if (num2>=num1&&num2>num3&&num2>num4)
cout<<"The Second Highest is "<<num2<<endl;
else if (num3>=num1&&num3>num2&&num3>num4)
cout<<"The Second Highest is "<<num3<<endl;
else if (num4>=num1&&num4>num2&&num4>num3)
cout<<"The Second Highest is "<<num4<<endl;
}
}
system("pause");
return 0;
}

Mr.Bernie Fabito

You might also like