954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

My Book Assignment

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;
}
grisha83
Junior Poster in Training
70 posts since Sep 2008
Reputation Points: 36
Solved Threads: 0
 

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

obj7777
Newbie Poster
8 posts since Sep 2008
Reputation Points: 30
Solved Threads: 0
 
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.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

You can use letter.compare() .

ithelp
Nearly a Posting Maven
Banned
2,230 posts since May 2006
Reputation Points: 769
Solved Threads: 128
 

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

Sci@phy
Posting Whiz in Training
279 posts since Sep 2008
Reputation Points: 110
Solved Threads: 43
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You