please write as a program language (C++) Thanks you! Write an if-else statement
ID: 3842521 • Letter: P
Question
please write as a program language (C++)
Thanks you!
Write an if-else statement to print the (double) quotient of 1/x, if, for a given integer x, x notequalto 0, and to print "ERROR" otherwise. Write a program to determine, and output to the screen, the class of an earthquake, given its magnitude. A class of minor is given for those in the range of [0, 4), light if in [4, 5), moderate if in [5, 6), strong if in [6, 7), major if in [7, 8) and great if in [8, infinity). Write a program to guess a magic number m = 4, and output to a file, each of guesses that are made. A sequence of random numbers is generated, each in the range [1, 10]. If the number is equal to m, then the program terminates. Otherwise, it generates another number. Your submission should include the contents of the output file using a random number generator seed of 760.Explanation / Answer
to print the quotient
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int num;
cout<< "Enter any integer";
cin>>num;
cout<<" ";
if(num == 0){
cout<<"Error!";
exit(0);
}
else
{
double quo = 1/num;
cout<<"Quotient is "<<quo<<endl;
}
return 0;
}
1.
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int mag;
cout<< "Enter the magnitude of earthquake";
cin>>mag;
cout<<" ";
if(mag>=0 && mag<=4)
cout<<"Minor"<<endl;
else if(mag>4 && mag<=5)
cout<<"Light"<<endl;
else if(mag>5 && mag >=6)
cout<<"Moderate"<<endl;
else if(mag>6 && mag<=7)
cout<<"Strong"<<endl;
else if(mag>7 && mag <=8)
cout<<"Major"<<endl;
else if(mag>8)
cout<<"Great"<<endl;
else
cout<<"Invalid number!"<<endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.