473,385 Members | 1,372 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

newb question

when using CIN
How do i make it so user input can be 5 or 6 letters
and
how do i put input into an if else statement ?
Example, i want the user to be able to input a word then program to decide
what word to spit out.

char input;
cout<<"Hi ";
cin>>input
if (input= = "Hello" ){
cout<<"Hello\n";
}
else{
cout<<"goodbye\n";
}
?
TIA
Jul 22 '05 #1
2 1162
Mitch wrote:
when using CIN
How do i make it so user input can be 5 or 6 letters
and
how do i put input into an if else statement ?
Example, i want the user to be able to input a word then program to decide
what word to spit out.


The IMHO best way to do this is to use the getline function defined in
<string> and teh strings themselves, consider the following code (untested)

#include <iostream>
#include <string>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::getline;

int main(int argc, char *argv[])
{
string input;

cout << "Hi " << endl;
getline(cin, input);
if(input == "Hello"
cout << "Hello" << endl;
else
cout << "Bye!" << endl;
return(0);
}

HTH && Kind regards,
Nicolas
Jul 22 '05 #2
thank you so much
I apreciate it..

"Nicolas Pavlidis" <ao***********@aon.at> wrote in message
news:33*************@individual.net...
Mitch wrote:
when using CIN
How do i make it so user input can be 5 or 6 letters
and
how do i put input into an if else statement ?
Example, i want the user to be able to input a word then program to decide what word to spit out.

The IMHO best way to do this is to use the getline function defined in
<string> and teh strings themselves, consider the following code

(untested)
#include <iostream>
#include <string>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::getline;

int main(int argc, char *argv[])
{
string input;

cout << "Hi " << endl;
getline(cin, input);
if(input == "Hello"
cout << "Hello" << endl;
else
cout << "Bye!" << endl;
return(0);
}

HTH && Kind regards,
Nicolas

Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: claudel | last post by:
Hi I have a newb PHP/Javascript question regarding checkbox processing I'm not sure which area it falls into so I crossposted to comp.lang.php and comp.lang.javascript. I'm trying to...
0
by: David E. | last post by:
So as a programmer, what's the best thing to study? EJB? How much of the J2EE or Enterprise architecture is necessary to no? I guess I need a good overview for a newb like me... thanks.. --...
3
by: Walter | last post by:
But I'm stumped..... I've got a windows 2000 server and I am trying to set up PHPBB on it using a mysql database.. I am very inexperienced on this..... Ive installed mysql V4.0.20d and I can...
3
by: claudel | last post by:
Hi I have a newb PHP/Javascript question regarding checkbox processing I'm not sure which area it falls into so I crossposted to comp.lang.php and comp.lang.javascript. I'm trying to...
6
by: Sean Berry | last post by:
Hello all I have build a list that contains data in the form below -- simplified for question -- myList = ,, ...] I have a function which takes value3 from the lists above and returns...
5
by: none | last post by:
hi all, (i am running on win 2k pro). i saw a program i like on a website and when i went to download it it was just a load of 'c' code. now, i know very little about 'c' or programming but...
2
by: python programming newb | last post by:
Hi all, first post. I'm new to python and tkinter. I'm trying to write a program that opens the root window with a button that then opens a toplevel window that then has it's own widgets. I...
2
by: J | last post by:
Greetings Group- I'm trying to put together a pattern matching script that scans a directory tree for tif images contained in similar folder names, but running into a NewB problem already. Is it...
1
by: jgibbens | last post by:
First, thank you for even looking at my question. I am using VB 2005 and I have a question about XML. what I want to do is: 1. keep adding to this file with out over writing it 2. be able...
3
by: DaveJ | last post by:
Hi everyone, I really was hesitant to post here for fear of seeming foolish but I really am desparate, and do appreciate any opportunity to get answers from real people. So please forgive the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.