hi!!
I need a help with part of my assignment. My professor asks to write a program that uses switch, and while loop statements..
this is the Exercise
Write a program that uses switch, and while loop statements to present the following menu and perform the operations.
Our program is able to offer the following:
1.Output all odd numbers between two integers.
2.Output the sum of all even numbers between two integers.
3.Output the integer numbers and their squares between two integers.
4.Output the sum of the square of the odd numbers between two integers.
5.Exit this program.
and I have done the First , the second and the fourth
in the fifth I don't understand what does it mean to "exit this program" so I did it like I always do >>return 0;<<...
in the third one i did it <<with no errors>>like this
i=firstNum;
j=secondNum;
cout<<"\nNumber\tSquares";
//Begin loop (while)
while (i<=j)
{
cout<<"\n"<<i<<"\t"<<i*i;
i++;
}//end loop (while)
when I run it it does not give me anything ..
but when I do it like this
i=1;
j=10;
cout<<"\nNumber\tSquares";
//Begin loop (while)
while (i<=j)
{
cout<<"\n"<<i<<"\t"<<i*i;
i++;
}//end loop (while)
when I run it is gives me the right answer
and Thank you so much
this is the program that I wrote ... and if there is anything wrong I did<<without realizing>> please inform me
//header file
#include<iostream>
using namespace std;
int main()// Begin Function
{
//declare variables
int firstNum, secondNum;
int sum_even,odd_sumsquare,i,j;
sum_even=0;
odd_sumsquare=0;
//Prompt and read the First Number and The Secondfrom the user
cout<<"\nEnter First Number: ";
cin>>firstNum;
cout<<"\nEnter Second Number: ";
cin>>secondNum;
//and now the Calculations
cout<<"\nODD Numbers: ";
//Begin loop (while)
while (firstNum<=secondNum)
{
switch (firstNum%2)//Begin switch
{
case 0:
sum_even+=firstNum;
break;
case 1:
cout<<" "<<firstNum;
odd_sumsquare+=firstNum*firstNum;
}//end switch
firstNum++;
}//end loop (while)
//output Numbers and squares between The First Number and The Second.
i=firstNum;
j=secondNum;
cout<<"\nNumber\tSquares";
//Begin loop (while)
while (i<=j)
{
cout<<"\n"<<i<<"\t"<<i*i;
i++;
}//end loop (while)
cout<<"\nSum of all even Numbers: "<<sum_even;
cout<<"\nSquares of Odd Numbers: "<<odd_sumsquare<<"\n";
return 0;
}//End Function
Thanks a lot....