(Y/N) Question

Mar 11, 2013 at 8:32pm
Hello. I need to make two different if statements according to users input. User have two choices (Y/N). How can I make if statements according to users input.

1st statement
if user says Y first statement ..

2nd statement
if user says N second statement ..
Mar 11, 2013 at 8:50pm
closed account (Dy7SLyTq)
if variable == 'Y'
Mar 11, 2013 at 9:35pm
fair enough ..
Mar 11, 2013 at 9:36pm
closed account (Dy7SLyTq)
sorry not trying to be difficult. was there something else you were looking for?
Mar 11, 2013 at 10:41pm
...
Last edited on Mar 11, 2013 at 11:13pm
Mar 11, 2013 at 10:49pm
closed account (3qX21hU5)
void Tomato(std::string name, char answer1);

When dealing with only 1 character like 'Y' or 'N' you should use the char variable type.

Mar 11, 2013 at 10:51pm
closed account (Dy7SLyTq)
yes. string would be "Y". i did not know you were using strings
Mar 11, 2013 at 10:55pm
well i had tried it before string but i got a strange error

Error 1 error LNK2019: unresolved external symbol "void __cdecl Tomato(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?Tomato@@YAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "void __cdecl Budget(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,double)" (?Budget@@YAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@N@Z) d:\Users\\documents\visual studio 2010\Projects\Homework2\Homework2.obj
Mar 11, 2013 at 10:59pm
either way string or char i get the same error
Mar 11, 2013 at 11:01pm
That is not a syntactical error; that's a linker error. Are you using multiple files? What's your project look like?
Mar 11, 2013 at 11:06pm
...
Last edited on Mar 11, 2013 at 11:12pm
Mar 11, 2013 at 11:08pm
Your prototype for Tomato() doesn't match the implementation.
Mar 11, 2013 at 11:12pm
that's embarrassing thanks
Mar 11, 2013 at 11:34pm
use &&
instead of ||

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;


int main ()
{
    char answer1;
	cout << ", do you want to buy some tomato? (Y/N):";
	cin >> answer1;

	if ( answer1 != 'Y' && answer1 != 'N')
			cout << ", you have entered an incorrect character.";

    return 0;
}
Mar 11, 2013 at 11:35pm
hmm yeah you're right
Last edited on Mar 11, 2013 at 11:37pm
Mar 11, 2013 at 11:38pm
closed account (3qX21hU5)
Also please don't delete your posts it is VERY ANNOYING since we can't follow the conversation and other people that search this forum for the same answer won't be able to get help from this thread.

I'm almost to the point of reporting users for doing this but I'm resisting because I'm probably overreacting to a pet peeve of mine.

Mar 11, 2013 at 11:43pm
cant share..
Last edited on Mar 18, 2013 at 3:21pm
Mar 12, 2013 at 12:17am
What? So you post on here to get help with your homework but will do whatever you can to prevent anyone else from learning what you did?
Topic archived. No new replies allowed.