Ver Mensaje Individual
  #1 (permalink)  
Antiguo 02/09/2006, 18:35
pedro_cesar
 
Fecha de Ingreso: septiembre-2006
Mensajes: 328
Antigüedad: 17 años, 9 meses
Puntos: 3
Help with "if"

I'm trying to create a friendly aplication that finds areas and perimeters and this is my code:

#include <iostream>

using namespace std;

int main (void) {
string name;

cout<<"Hi, What's your name? ";
cin>> name;

cout<<"Oh, hi "<<name<<", my name is Pedro!\n";

int a;
int b;

cout<<"How old are you? ";
cin>> a;

if (a<17) {

b = 17-a;
cout<<"Wow! I'm "<<b<<" years older than you!\n";

} else if (a==17) {

cout<<"Cool! We're the same age!\n";

}else if (a ==18) {

cout<<"You are 1 year older than me!\n";

} else if (a>18) {

b = a-17;
cout<<"Oh, I see, you are "<<b<<" years older than me!\n";
}

int shape;
int command;

cout<<"..........\n";
cout<<"\n";
cout<<" Although I'm relatively young I can accomplish many mathematical tasks, since \nyou're my BUDDY now, you don't mind me showing you, do you?\n";
inicio:
cout<<"\n";
cout<<"What shape would you like me to calculate something of?\n";
cout<<"1.- Square 2.-Rectangle 3.-Triangle 4.-Circle\n";
cin>> shape;
cout<<"\n";
cout<<"What do you want me to find?\n";
cout<<"1.- Area 2.-Perimeter\n";
cin>> command;
cout<<"\n";

int sizes;
int sizesp;
int rsize;
int rsizeh;
int rsizep;
int rbase;
int rhgt;
float x, x1, x2;


if (shape ==1, command ==1) {
cout<<"Enter the measure of one side: ";
cin>>sizes;

cout<<"The Result is: "<<sizes*sizes;
cout<<"\n";
cout<<"\nPress 1 if you wanna start over\nPress 2 if you wanna quit\n";
cin>> x;
if (x ==1) {
goto inicio;
}
if (x ==2) {
goto end;
}
}

if (shape ==1, command ==2) {
cout<<"Enter the measure of one side: ";
cin>>sizesp;

cout<<"The Result is: "<<sizesp*4<<"\n";
cout<<"\nPress 1 if you wanna start over\nPress 2 if you wanna quit\n";
cin>> x1;
if (x1 ==1) {
goto inicio;
}
if (x1 ==2) {
goto end;
}
}

if (shape ==2, command ==1) {
cout<<"Enter the size of the base: ";
cin>>rsize;

cout<<"Enter The Height: ";
cin>>rsizeh;

cout<<"The Result is: "<<rsize*rsizeh;
cout<<"\n";
cout<<"\nPress 1 if you wanna start over\nPress 2 if you wanna quit\n";
cin>> x;
if (x ==1) {
goto inicio;
}
if (x ==2) {
goto end;
}
}
end:;
}


My problem is the following: If I choose rectangle the code takes me to square's code anyways.

What do I have to do for the code to take me to rectancle's code when I type 2 for shape.