C++ while loop being ignored please help!!!!

closed account (y0R9216C)
//Assignment #3

#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
int lowNum;
int highNum;
int sumEven;
sumEven = 0;
int mod = lowNum % 2;


// prompt the user to enter two numbers
cout << "Please enter a low number: ";
cin >> lowNum;
cout << "You entered: " << lowNum << "." << endl;

cout << "Please enter a high number: ";
cin >> lowNum >> highNum;
cout << "You entered: " << highNum << "." << endl;


while (lowNum < highNum )
{

// check for odd number.
if( mod == 0 )
{
sumEven += lowNum;
lowNum++;
cout << lowNum << endl;
lowNum += 2;
cout << lowNum << endl;
}
else
{
cout << lowNum << endl;
lowNum += 2;
cout << lowNum << endl;
}
cout << sumEven << endl;

}

return 0;
}

for sum reason all it does is the first input and then it doesn't go down into the while loop, btw im using g++ with command prompt to compile and run the program. When I use a site like codepad.org it just inputs values over and over forever...idk whats wrong ive been working on this for days i can't figure it out please help.
Last edited on
Ok it is late and i might get some things wrong, but on quick glance, this is what i notice.

your line asking for input of a highNum should be:

cin >> highNum

get rid of the lowNum part in the line.

Where you have your mod value, just leave it as int mod. Then put mod = lowNum % 2 after you have actually been given the values by the user (as in after cout << "You entered: " << highNum << "." << endl;)

as for the rest of the code im not sure what you are trying to do but your while loop should run now.
closed account (y0R9216C)
Yeah i figured it out thank you i was adding highnum into lownum so they were just equal and would not loop, thanks and as for the loop itself that code above is wrong but basically it just prints all the odd numbers in between the low num and high num and then prints out the total sum of all the even numbers in between.
Topic archived. No new replies allowed.