Switch to full style
For C/C++ coders discussions and solutions
Post a reply

C++ help with writing a program.

Thu Oct 04, 2012 10:19 pm

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;
}



Post a reply
  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?     -  
 java program     -  
 how can i DeployPHP Program     -  
 what is the output of this program and how it be?     -  
 Write a program in C++     -  
 write a program in c++ for the following...     -