Total members 11895 |It is currently Sat Dec 21, 2024 4:57 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Write a program that uses 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
~output the sum of the square of the odd numbers between firstNum and secondNum
~output all uppercase letters

Then I have to write a for loop program and a do...while loop program performing the same steps. If I could just figure out the while loop, it would help me write the other 2 programs.

I have this, but I'm not entirely sure if it is right or not:

#include <iostream>
using namespace std;
int main ()
{
int firstNum=0, secondNum=0;
int sum=0;
int sumSquares=0;

cin >> firstNum;
cin >> secondNum;
while (firstNum<secondNum)
{cout << "Enter first number: ";
cout << "Enter second number: ";
if(firstNum>secondNum)
{cout << "Your First Number is greater than second.So Please re-enter: ";}
else{cout << "Odd Numbers: ";
while(firstNum <= secondNum)
{if(firstNum%2 != 0)
{cout << firstNum;
sumSquares+=firstNum*firstNum;
}
if(firstNum%2 == 0)
{sum+=firstNum;}
firstNum++;
}
cout << "Sum Of Even Numbers: "+sum;
cout << "Numbers and their squares between 1 and 10";
int i=1;
while(i <= 10)
{cout << i+" "+i*i;
i++;}
cout <<"Sum Of square of odd Numbers: "+sumSquares;}
}
return 0;
}




Author:
Newbie
User avatar Posts: 2
Have thanks: 1 time

For this message the author ashleydawn97 has received gratitude : amitmandal1991
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : C++ help with writing a program.
 Writing a Counter to any PORT     -  
 Read XML file content using SAX and writing its as SQL     -  
 Reading and Writing To text file     -  
 Writing a Windows Form Application For .NET Framework Using     -  
 HOW TO DO C++ PROGRAM?     -  
 Write a program in C++     -  
 write a program in c++ for the following...     -  
 run .exe program in matlab     -  
 Need help in Chatting Program     -  
 java program     -  



cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com