(Y/N) Question

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 ..
closed account (Dy7SLyTq)
if variable == 'Y'
fair enough ..
closed account (Dy7SLyTq)
sorry not trying to be difficult. was there something else you were looking for?
Last edited on
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.

closed account (Dy7SLyTq)
yes. string would be "Y". i did not know you were using strings
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
either way string or char i get the same error
That is not a syntactical error; that's a linker error. Are you using multiple files? What's your project look like?
Last edited on
Your prototype for Tomato() doesn't match the implementation.
that's embarrassing thanks
use &&
instead of ||

#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;
hmm yeah you're right
Last edited on
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.

cant share..
Last edited on
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.