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
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
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
You can use letter.compare() .
ithelp
Nearly a Posting Maven
2,230 posts since May 2006
Reputation Points: 769
Solved Threads: 128