Creating Seperate If Statements

I'm attempting to create a simple program that a user can type a char variable into and it will generate info on the word. I'm trying to use if statements, like "if" they type apple you get info on apples, "if" pears you get pears, but whenever I add the second if statement in, it shows results from both the apple and bear if statements.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <string>

using namespace std;
int main()
{
	//Declaring and Initializing Variables
	char fruitName[50];

	cout << "Please Specify a Fruit:\n";
	cin >> fruitName;
		
		if(fruitName=="Apple")
		{
			cout << "Apples are nice.";
			
		}
			
		if(fruitName=="Pear")
		{
			cout << "Pears are nice.";

}
1) You are missing a brace for your second if statement
2) You cannot compare C-strings with ==. Use strcmp from the <cstring> header.
http://www.cplusplus.com/reference/cstring/strcmp/?kw=strcmp
3) You do include the <string> header and you are programming in C++, so why not use std::string? With std::string, you can use == to compare.
 
string fruitName("");
Topic archived. No new replies allowed.