Pick any one topic of the following and Post an initial message Cwte 10 300 Disc
ID: 3588808 • Letter: P
Question
Pick any one topic of the following and Post an initial message Cwte 10 300 Discussion Topics: 1. Provide your own short C++ code example that uses an if-else statement and two relational operators. Be sure to test and explain your code 2. Provide your own short C++ code example that uses math operators of your choice. Try to use at least 3 different Math operators (e.g., +, -, *, /, %). Be sure to test and explain your code. While your initial responses to Discussions assignments should be concise (100-300 words), they should also be written with accepted conventions of standard American English. In other words, capitalize, punctuate and check spelling!Explanation / Answer
1)
#include <iostream>
using namespace std;
int main()
{
float n1, n2, n3;
cout << "Enter three numbers: ";
cin >> n1 >> n2 >> n3;
if(n1 >= n2 && n1 >= n3)
{
cout << "Largest number: " << n1;
}
if(n2 >= n1 && n2 >= n3)
{
cout << "Largest number: " << n2;
}
if(n3 >= n1 && n3 >= n2) {
cout << "Largest number: " << n3;
}
return 0;
}
Output:
Enter three numbers: 6 4 9
Largest number: 9
relational operators are mostly used for the purpose of comparision the main three relational operators are =,>,<.The above program is about the finding the largest among the three numbers.Here the first number n1 compared with other two n2 and n3.Similarily the comparision is done for the other numbers too.
2)
#include <iostream>
using namespace std;
int main()
{
float n1, n2, n3;
int op;
cout<<"Enter the choice: 1.Add 2.sub 3.multiply";
cin>>op;
cout << "Enter numbers: ";
cin >> n1 >> n2;
switch(op)
{
case 1:
n3=n1+n2;
break;
case 2:
n3=n1-n2;
break;
case 3:
n3=n1*n2;
break;
default:
exit;
}
cout<<"Results are"<<n3;
return 0;
}
Enter the choice:
1.Add
2.sub
3.multiply
1
Enter numbers:3 4
Results are7