MuffinMan
Juno 15/4/08 :)
I have no idea why this program hangs when i type a positive integer greater than 1
The idea of the code is to add all the numbers from 1 to the number the user has inputted except when num mod 3 == 0, num < 10 && num mod 2 == 0;
HELP!!!!
code:
The idea of the code is to add all the numbers from 1 to the number the user has inputted except when num mod 3 == 0, num < 10 && num mod 2 == 0;
HELP!!!!
code:
Code:
#include <iostream>
using namespace std;
int main()
{
int sum, endingInteger, startingInteger = 1;
cout <<"Enter an integer" << endl;
cin >> endingInteger;
while (endingInteger < 1)
{
cout <<"Error! you have entered an invalid value" << endl;
cin >> endingInteger;
}
while (endingInteger > startingInteger)
{
while (endingInteger >= 1)
{
while (startingInteger <= 10)
{
switch (startingInteger % 2)
{
case 0: sum == sum;
startingInteger++;
break;
case 1: sum = sum + startingInteger;
startingInteger++;
}
}
}
while (startingInteger > 10)
if (startingInteger % 3 != 0)
{
sum = sum + startingInteger;
startingInteger++;
}
else
{
sum == sum;
startingInteger ++;
}
}
cout <<" START\t" <<" END\t" << "SUM" << endl;
cout << " 1\t" << " \t" << endingInteger << " \t " << sum << endl;
return 0;
}
Last edited by a moderator: