Oct 21, 2011 at 7:53am Oct 21, 2011 at 7:53am UTC
can anyone help me im just a newbie programer...
and this is my problem
i need a program that i can put a number then will prompt low if the value is lower or equal to 99 and prompt high if the value i higher than or equal to 100
thank you all i wish someone help me ^_^
jonpaul...
Oct 21, 2011 at 8:06am Oct 21, 2011 at 8:06am UTC
#include <iostream>
#include <string>
#include <sstream>
int main(int argc, char ** argv)
{
std::cout << " enter your number ";
int number;
std::string input;
while(true)
{
getline(std::cin,input); //Recieve number from user.
std::stringstream temp(input);
if (temp >>number)
{
if (number >= 100)
std::cout << "HIGH";
else if (grade <= 99)
std::cout << "LOW";
else
{
std::cout << "plx enter a number again;
}
std::cout << std::endl <<number;
break;
}
else std::cout << "Invalid number, please try again: ";
}
getchar();
}
this is the program and it will not run what is the problem?
hmmmm and btw sorry for posting here and not in beginners threads
Oct 21, 2011 at 8:11am Oct 21, 2011 at 8:11am UTC
Please use [ code][/ code] tags (without the spaces). It takes care of proper layout and allows us to refer to line numbers.
Also, be more specific in your problem. How does it 'not run'? Compile errors? Does-nothing-then-quits? Or simply doesn't do what you ask?
For one thing, there's a mistake in this line: if (temp >>number)
. ">>" is the "extract" operator, ">" is the "greater than" comparison operator.
Oct 21, 2011 at 8:17am Oct 21, 2011 at 8:17am UTC
getline is a member of std isn't it?
number is also never assigned a value which may cause undefined behavior.
Last edited on Oct 21, 2011 at 8:20am Oct 21, 2011 at 8:20am UTC
Oct 21, 2011 at 8:38am Oct 21, 2011 at 8:38am UTC
Wait, I just realized what he tried to do. He's trying to read in number through the stream 'temp'. I'm not sure you're using it right...