#include <iostream>
usingnamespace std;
int main()
{
calc:
system ("cls");
char ans;
int length;
int width;
int area;
int perimeter;
cout << "Input The Length Of The Rectangle: " << endl;
cin>> length;
cout << "Input The Width Of The Rectangle: " << endl;
cin>> width;
perimeter = 2 * (length + width);
area = length * width;
cout << "The Perimeter Of The Rectangle Is: "<< perimeter << endl;
cout << "The Area Of The Rectangle Is: "<< area << endl;
system("PAUSE>NUL");
choice:
system("cls");
cout << "What Do You Want To Do?" << endl;
cout << "(A) Calculate Another Rectangle's Area And Perimeter." << endl;
cout << "(B) Quit The Program." << endl;
cin>> ans;
if(ans == 'A' || ans == 'a');
{
goto calc;
}
elseif(ans == 'B' || ans == 'b');
{
exit (1);
}
else
{
cout << "Illegal Choice You DumbArse" << endl;
system("Pause>nul");
goto choice;
}
}
This is my code. Its Job Is To Calculate A Rectangle's Area And Perimeter. In The End I Have Added 2 Choices. A and B. A Is to do it again. B is to exit. I get these errors while compiling:
warning C4390: ';' : empty controlled statement found; is this the intent? error C2181: illegal else without matching if
warning C4390: ';' : empty controlled statement found; is this the intent?
error C2181: illegal else without matching if
If It Helps I Am Usin Windows 7 and using visual c++ 2008 express. I know i should search the forums for such errors before posting, but ihave and i did not find anything like this. if there is such a topic i would be glad if you send me a link. And If you dont mind, explain the warnings to me. Thanks!
Thanks Alot Script Coder And TheIdeasMan, And I Will Consider While Loops!
Its Just That Im trying to make the code smaller , because when i actually finish thewhole program, its gonnabe for all shapes, at the user's choice, and there will be 3 choices, exit, again, again with dif shape ;D Anyways thanks alot!!
It use classes, (you don't have to do that if you don't want to), but the main() shows the ShowMenu & ProcessMenu functions. You could extend it with functions for each menu option.
Have a go, see how you get on.
Its Just That Im trying to make the code smaller
If you use functions properly, it will make your code more concise.
Also consider using local variables in your functions.
TheIdeasMan, If you could make what u just said a bit easier, because i just started learning c++, and barely know anything :P Thanks For the help btw!
void ShowMenu() {
cout << "Welcome to My Banking System\n\n" ;
cout << "(1) Add account\n";
cout << "(2) Delete Account\n";
cout << "(3) Account Inquiry\n";
cout << "(4) Save Accounts to File\n";
cout << "(5) Load Accounts from File\n";
cout << "(6) Exit\n\n";
cout << "Please Enter your Selection" << endl;
}
can be rewritten as
1 2 3 4 5 6 7 8 9 10 11 12 13
inlinevoid ShowMenu( std::ostream &os = std::cout )
{
constchar *menu = "Welcome to My Banking System\n\n""(1) Add account\n""(2) Delete Account\n""(3) Account Inquiry\n""(4) Save Accounts to File\n""(5) Load Accounts from File\n""(6) Exit\n\n""Please Enter your Selection";
os << menu << std::endl;
}
I saw your PM's, I would rather not communicate this way unless there is a good reason.
I saw the code you posted, it is the same as before. You haven't answered the questions I asked - I would like to see something more substantial from you.
I am beginning to wonder if you are trolling.
If not, show us something to prove otherwise.
Sorry if I sound harsh, but I am not going to sit here all night, putting effort in - and not seeing any results.
I am pleased to help, but I need to see something from you.
@Techy24
Actually You Are Wrong, Its Is 'Else If' not 'ElseIf'
@TheIdeasMan
I am beginning to wonder if you are trolling.
I Am Sorry That You Think That Way, But I Asure You, I Am Not Trolling At All.
@TheIdeasMan
Sorry if I sound harsh, but I am not going to sit here all night, putting effort in -and not seeing any results.
I am pleased to help, but I need to see something from you.
You Do Not Sound Harsh At All, Because You Have A Huge Point Here, And I Agree With You,But Take It Easy On Me, Because I Do Not Open The Internet Often, AND I am Just 11 years old, and this may be a bit hard for me to understand, but my passion to learning programming is how i survive :)