dugindog
10-19-2005, 09:03 PM
again yes this is homework, the objective is basically exactly what I am doing, however I want to take it 1 step further.
the code is functional for the assignment, however I am looking at a error that is occuring with it (only if I enter a non-integer number / decmial) it seems to go into a funky loop. the assignment only requires integers, however I am not satisfied with that, could someone please take a look at the code and possibly explain why it does that, I'm assuming that is is because of the variable type (int), if someone could give a sugestion for it I would be greatly appreciative.
thanks
#include "stdafx.h"
#include<iostream>
using namespace std;
int main(int argc, char* argv[])
{
int num1;
while( num1 != 0 )
{
std::cout << "Enter An Integer: " << std::endl;
std::cin >> num1;
if (num1 > 0)
std::cout << "The number is Positive." << std::endl;
if (num1 < 0)
std::cout << "The number is Negative." << std::endl;
}
return 0;
}
the code is functional for the assignment, however I am looking at a error that is occuring with it (only if I enter a non-integer number / decmial) it seems to go into a funky loop. the assignment only requires integers, however I am not satisfied with that, could someone please take a look at the code and possibly explain why it does that, I'm assuming that is is because of the variable type (int), if someone could give a sugestion for it I would be greatly appreciative.
thanks
#include "stdafx.h"
#include<iostream>
using namespace std;
int main(int argc, char* argv[])
{
int num1;
while( num1 != 0 )
{
std::cout << "Enter An Integer: " << std::endl;
std::cin >> num1;
if (num1 > 0)
std::cout << "The number is Positive." << std::endl;
if (num1 < 0)
std::cout << "The number is Negative." << std::endl;
}
return 0;
}