Answer to Question #262661 in C++ for Glady_07

Question #262661

Create a program that will ask a user to enter a number. Depending on the value that the user has entered the program will do the following:


*If the user has entered the number 0, the program will display the first 50 multiples of 4.


*If the user has entered a negative number, the program will display all odd numbers between 20 and 80.


*If the user has entered a number between 1 and 10 (inclusive of the 2), the program will dsiplay all even numbers from 1 to 500.


*If the user has entered any other number, the program will display the world "Hello" n number of times where n's value will depend on the number the user has entered.

1
Expert's answer
2021-11-08T09:13:32-0500
#include <iostream>
using namespace std;


int main() {
    int number;
	//enter a number. 
	cout << "Enter a number: ";
    cin >> number;
	//Depending on the value that the user has entered the program will do the following:
	//*If the user has entered the number 0, the program will display the first 50 multiples of 4.
	if(number==0){
		for(int i=0;i<=50;i++){
			int product=i*4;
			cout<<i<<" * 4 = "<<product<<"\n";
		}
	}else
	//*If the user has entered a negative number, the program will display all odd numbers between 20 and 80.
	if(number<0){
		cout<<"\nAll odd numbers between 20 and 80: \n";
		for(int i=20;i<=80;i++){
			if(i%2==1){
				cout<<i<<"\n";
			}
		}
	}else
	//*If the user has entered a number between 1 and 10 (inclusive of the 2), the program will dsiplay all even numbers from 1 to 500.
	if(number>=1 && number<=10){
		cout<<"\nAll even numbers from 1 to 500: \n";
		for(int i=1;i<=500;i++){
			if(i%2==0){
				cout<<i<<"\n";
			}
		}
	}else{
		//*If the user has entered any other number, the program will display the world "Hello" n number of 
		//times where n's value will depend on the number the user has entered.
		for(int i=1;i<=number;i++){
			cout<<"Hello\n";
		}
	}


	cin>>number;
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Glady_07
09.11.21, 04:53

Thank you so much. Your answer is a big help to me

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS