high and low

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...
How did you manage to type that first sentence without realizing you'd be better off posting in the "Beginners" forum?

Anyway, all you need is:
a) A way to grab input. Include <iostream> and use "cin": http://www.cplusplus.com/reference/iostream/cin/
b) A way to compare the input to another value. Use 'if' conditionals: http://www.cplusplus.com/doc/tutorial/control/
c) A way to output the "result". Use "cout": http://www.cplusplus.com/reference/iostream/cout/
#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
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.
getline is a member of std isn't it?

number is also never assigned a value which may cause undefined behavior.
Last edited on
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...
Topic archived. No new replies allowed.