So, I joined DaniWeb in february, and posted a problem regarding this code. I then quit learning for a while, and started again a week ago or so, continuing this. I've made it better, and its almost working, except for the If statement doesnt work. It asks you what you want to do, and no matter what letter you put in, it will run the rectangle area function, then right after, run the volume function, then end the program.
I really dont know whats up, but it could be the getline(cin, chooseType); thats messing up, im not sure.
also if theres any thing I can do to make my code look better, will be appreciated ;)
help please? :P
(remember im a beginner)
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
int triangularPrism(); // global variables
int rectangleArea(); // global variables
int main() {
string chooseType; // variables
system("color 0c");
cout << "What would you like to do?" << endl << endl;
cout << "Press A to work out the area of a rectangle,\nor V to work out the volume of a triangular prism. \n"; // choice
getline(cin, chooseType);
cin.clear();
if(chooseType == "a" || "A"){ //if statement, "a" chooses area of rectangle
rectangleArea();
}
if(chooseType == "v" || "V"){ //second if, "v" chooses volume of triangular prism
triangularPrism();
}
return 0;
}
int rectangleArea() {
int rectangleLength, rectangleWidth, rectangleArea;
cout << "Enter the length of the rectangle: ";
cin >> rectangleLength;
cout << "Enter the width of the rectangle: ";
cin >> rectangleWidth;
rectangleArea = rectangleLength * rectangleWidth;
cout << "\n \n";
cout << rectangleLength << " x " << rectangleWidth << " = " << rectangleArea;
cout << "\nThe area of the rectangle is: " << rectangleArea << "\n \n";
cout << "Press any key to exit. \n" << endl;
getch();
return 0;
}
int triangularPrism() {
double triangularLength, triangularBase, triangularHeight;
cout << "Enter the length of the Triangular Prism: ";
cin >> triangularLength;
cout << "Enter the base, otherwise known as width: ";
cin >> triangularBase;
cout << "Enter the height: ";
cin >> triangularHeight;
cout << "\n" << triangularLength << " times " << triangularBase << " times " << triangularHeight << " divided by 2 " << "\n" "(" << triangularLength << "*" << triangularBase << "*" << triangularHeight << "/2" << ")" "\n";
cout << "The volume of the Triangular Prism is: " << triangularLength * triangularBase * triangularHeight / 2 << endl;
cout << "Press any key to exit. \n" << endl;
getch();
return 0;
}