Hello,
I am trying to do this assignment in the book. My objective is to create an interactive program which will calculate areas of a square or a triangle depending on the user input 's' or 't'. I am gone about 40% of the book so they dont expect me to use any kind of fancy stuff, just using If statement
Anyhow, here is my code and the errors are C2676 and C2784 in Visual Studio
Please tell me what i am doing wrong there
Thank you

// greg lyukshin
// chapter 4.4 program 2
// compound IF statement for area of the square and triangle

#include<cmath>
#include<iostream>
using namespace std;

int main()
{
	char s,
	        t;
	float area,
		  side,
		  base,
		  height;
	string letter;

	
	cout << "enter either 's' to find area of square or 't' to find area of triangle: " << endl;
	cin >> letter;
	
	if(letter == 's')
	{	cout << "enter side: " << endl;
		cin >> side;
		area = pow(side,2);
		cout << "area of square is " << area << endl;
	}
	else
		if(letter == 't')
	{	cout << "enter base: " << endl;
		cin >> base;
		cout << "enter height: " << endl;
		cin >> height;
		area = (1/2) * base * height;
		cout << "area of triangle is " << area << endl;
	}
	
	system("pause");
	return 0;
}

Use double quotes around t and s, since letter is a string.

Anyhow, here is my code and the errors are C2676 and C2784 in Visual Studio

Since we are humans, not compilers, C2676 and C2784 mean nothing. And even less because we don't know what lines caused the error.

Details, me bucko, details. They are important.

You can use letter.compare() .

The best thing is not to use string to hold only one letter (very bad idea). So instead of

string letter;

you better write:

char letter;

HTH

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.