Answer to Question #303308 in C++ for Becca

Question #303308

Write a program that uses do...while loops to perform the following steps:

  1. Prompt the user to input two integers: firstNum and secondNum
  • (firstNum must be less than secondNum).
  1. Output all odd numbers between firstNum and secondNum.
  2. Output the sum of all even numbers between firstNum and secondNum.
  3. Output the numbers and their squares between 1 and 10.
  • Separate the numbers by any amount of spaces.
  1. Output the sum of the square of the odd numbers between firstNum and secondNum.
  2. Output all uppercase letters.
1
Expert's answer
2022-02-27T07:03:04-0500


using namespace std;


/*
	Write a program that uses do...while loops to perform the following steps:


	Prompt the user to input two integers: firstNum and secondNum
	(firstNum must be less than secondNum).
	Output all odd numbers between firstNum and secondNum.
	Output the sum of all even numbers between firstNum and secondNum.
	Output the numbers and their squares between 1 and 10.
	Separate the numbers by any amount of spaces.
	Output the sum of the square of the odd numbers between firstNum and secondNum.
	Output all uppercase letters.
*/


int main()
{
	int firstNum=0,secondNum=0,n,Sum=0;
	
//	Prompt the user to input two integers: firstNum and secondNum
//	(firstNum must be less than secondNum).
	while(secondNum<=firstNum)
	{
		cout<<"\n\tEnter first  Number: "; cin>>firstNum;
		cout<<"\n\tEnter second Number: "; cin>>secondNum;
		cout<<"\n\tSecond Number should be greater than first Number.";
	}


//	Output all odd numbers between firstNum and secondNum.
	cout<<"\n\tOdd Numbers; ";
	Sum = 0;
	for(n=firstNum;n<=secondNum;n++)
	{
		if(n%2==1) cout<<n<<", ";
	}


//	Output the sum of all even numbers between firstNum and secondNum.
	cout<<"\n\n\tEven Numbers; ";
	for(n=firstNum;n<=secondNum;n++)
	{
		if(n%2==0) cout<<n<<", ";
	}


	cout<<"\n\n\tOutput the numbers and their squares between 1 and 10.";
//	Separate the numbers by any amount of spaces.
	for(n=firstNum;n<=secondNum;n++)
	{
		if(n<10) cout<<"\n\tNumber = "<<n<<"\tSquare("<<n<<") = "<<n*n;
	}
	


	cout<<"\n\n\tOutput the sum of the square of the odd numbers between firstNum and secondNum.";
	Sum = 0;
	for(n=firstNum;n<=secondNum;n++)
	{
		if(n%2==1) Sum = Sum + n*n;
	}
	cout<<"\n\tSum = "<<Sum;
	
	cout<<"\n\tOutput all uppercase letters.\n";
	for(n=0;n<26;n++) cout<<char('A'+n)<<" ";
	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

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog