First off: HI! Been lurking on here for a while now and decided to join at last. Love the site btw.
Anyway, I started the tutorial a day or two ago and took a shot at my first program. The goal is that I will be able to pick a shape and then input various measurements and the program will then take these and work out area, volume, etc using what equations I add.
My little program so far looks like this:
I've just added a little bit of content here and there to test everything and after it works well I can obviously tweak it.Code:#include <iostream> using namespace std; int main() { int shape; float PI = 3.141592654; float radius; float length; float height; float diameter; float width; float area; float volume; float base; cout << "Please choose a shape by typing its corresponding value and pushing enter:\n1-circle\n2-square\n3-triangle\n"; cin >> shape; cin.get(); if ( shape==1 ) { cout << "Type in the radius\n"; //circle cin >> radius; float area=(radius + radius) * PI; cout << "Area: "; cout << area; cout << "cm squared"; cin.get(); } else if ( shape==2 ) { cout << "square\nVolume:\nArea:\n"; //square } else if ( shape==3) { cout << "Type in the perpendicular height\n"; //triangle cin >> height; cout << "\n"; cout << "Type in the length of the base\n"; cin >> base; float area=0.5*(base*height); cout << "Area: "; cout << area; cout << "cm squared\n"; cin.get(); } else { cout << "Unrecognised shape"; } cin.get(); }
My first problem is that I cannot loop the program block. For example if someone inputs a shape that isn't supported and the cout "Unregistered shape" is prompted, I want the program to then reset back to the start of the main() rather than having to restart the whole program window again.
My other problem is that at the start when the user is prompted to pick a shape, I had to use a number to represent each variable instead of being able to just allow the input "circle" (for example) which would activate the next line of corresponding coding. I have read about strings and i tried the #include strings but I still can't get it to see the circle as a 1 or something which I can use in the "if" section.
(sorry that this is so long-winded, after reading the warnings prior to entering the message board section i'm terrified of under explaining myself thus invoking the wrath of the pro c++ pplz who are fed up with this kind of thing...I really have been looking things up and cannot come up with a solution, also skimmed ahead in the tutorial since i'm only on loops/functions and didn't find what I needed)
My final problem will arise after I figure out the looping program problem because the area, etc "float" variables will have been made to = something, will that mess up the next equations?
Thank you in advance. (Everyone seems to say that, sry if its presumptuous)