saiz66 Posted August 10, 2004 Share Posted August 10, 2004 Hi. I want to read in 3 seperate values that the user enters but they are sperated by spaces. So A 1 4, A is one value, 1 is another, and 4 is the third value. How would I do this? Thanks in advance. Link to comment Share on other sites More sharing options...
0 Genesi Posted August 10, 2004 Share Posted August 10, 2004 Let's try something new. I'll help but I want to see what you have tried first. Don't take this the wrong way but failing and trying at a language is the best way to learn. So, while I know what you need I would like to see what you have so far and I'll make a few suggestions. Link to comment Share on other sites More sharing options...
0 azcodemonkey Posted August 10, 2004 Share Posted August 10, 2004 saiz, have you even thought about buying a book or trying online tutorials first? http://cplus.about.com/library/blc++tutorials.htm?terms=c++ Link to comment Share on other sites More sharing options...
0 Genesi Posted August 10, 2004 Share Posted August 10, 2004 saiz, have you even thought about buying a book or trying online tutorials first?http://cplus.about.com/library/blc++tutorials.htm?terms=c++ More links and newsgroups here: http://www.function-pointer.org/links.html Link to comment Share on other sites More sharing options...
0 saiz66 Posted August 10, 2004 Author Share Posted August 10, 2004 ok i figured it out.. I just ask the user for the info: A 1 4 and the user types it in and I just have a cin >> type; cin >> vertex; cin >> vertex2; But I want it to quit asking for info when the user pushes 'q' .... But when I push 'q' it is still waiting for other values such as the vertex and vertex2... hmm.. not sure how to get around this. Link to comment Share on other sites More sharing options...
0 Genesi Posted August 10, 2004 Share Posted August 10, 2004 I'll give ya a hint: a while loop or a do while loop Link to comment Share on other sites More sharing options...
0 saiz66 Posted August 11, 2004 Author Share Posted August 11, 2004 haha.. this is the only thing i can think of: cout << "Enter the edge " << endl; cin >> type; while (type != 'q') { cin >> vertex; cin >> vertex2; } Link to comment Share on other sites More sharing options...
0 kjordan2001 Posted August 11, 2004 Share Posted August 11, 2004 haha.. this is the only thing i can think of:cout << "Enter the edge " << endl; cin >> type; while (type != 'q') { cin >> vertex; cin >> vertex2; } Well, that's fine if you repeatedly ask for a type (which you're not doing...what you've got there is an infinite loop since if they don't enter q the first time, it'll just keep asking for vertex and vertex2). If you're only asking once, check with an if statement. Link to comment Share on other sites More sharing options...
0 saiz66 Posted August 11, 2004 Author Share Posted August 11, 2004 but i am repeatedly asking for the three values and when I get them I do some code .. for example R 1 4... then i do some code... then i want to ask for 3 more values such as A 3 4.. but if the user enters just 1 value of Q..i want it to quit the program... Link to comment Share on other sites More sharing options...
0 kjordan2001 Posted August 11, 2004 Share Posted August 11, 2004 but i am repeatedly asking for the three values and when I get them I do some code .. for example R 1 4... then i do some code... then i want to ask for 3 more values such as A 3 4.. but if the user enters just 1 value of Q..i want it to quit the program... cin>>type; while (type != 'q') { cin >> vertex; cin >> vertex2; dosomething(); cin >> type; } finishup(); Link to comment Share on other sites More sharing options...
0 saiz66 Posted August 11, 2004 Author Share Posted August 11, 2004 thnaks a lot!!!!! i forgot to read it in again.. therefore i think i created an infinite loop... Link to comment Share on other sites More sharing options...
0 kjordan2001 Posted August 11, 2004 Share Posted August 11, 2004 thnaks a lot!!!!! i forgot to read it in again.. therefore i think i created an infinite loop... Yep, like I said, unless they enter q the first time, it would go into an infinite loop. Link to comment Share on other sites More sharing options...
Question
saiz66
Hi. I want to read in 3 seperate values that the user enters but they are sperated by spaces. So A 1 4, A is one value, 1 is another, and 4 is the third value. How would I do this? Thanks in advance.
Link to comment
Share on other sites
11 answers to this question
Recommended Posts