Menu system
Jeg her lige bakset et program sammen, et simpelt program til at regne på retvinklede trekanter ved hjælp at trigonometri, programmet kører fint så ingen spørgsmål der. Min problem er med menu systemet, jeg vil gerne have et bedre menu system, lige nu bruger jeg bare en switch..case ting, det virker også, men den eneste måde at lave et program der ikke afslutter efter en udregning er at lave en uendelig løkke og have en case der break'er loopet og return'er 0, det vil jeg gerne gøre noget ved så jeg kan få et lidt mindre 'klodset' system, og da jeg også bruger system("PAUSE"); og system("CLS"); for at sørge for at det ikke bare scroller forbi brugeren når den er færdig med en udregning har jeg også effektivt spræret programmet fra at blive brugt på andre OS'er..Anyways her er progget:
#include <iostream.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int choice = 0;
double SideA = 0;
double SideB = 0;
double SideC = 0;
double AngleA = 0;
double AngleB = 0;
double AngleC = 90;
double PI = 3.14159265;
while(1)
{
cout<<"Trig suite 1.0"<<endl
<<endl;
cout<<"Menu:"<<endl;
cout<<endl
<<"What numbers do you have?"<<endl
<<endl
<<"1. Side a and side b."<<endl
<<"2. Side b and side c."<<endl
<<"3. Side a and side b."<<endl
<<"4. Side c and Angle A."<<endl
<<"5. Side c and Angle B."<<endl
<<"6. Side a and Angle B."<<endl
<<"7. Side b and Angle A."<<endl
<<"8. Side a and Angle A."<<endl
<<"9. Side b and Angle B."<<endl
<<"0. Quit program."<<endl
<<"Enter your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"Enter lenght of side a in centimeters: ";
cin>>SideA;
cout<<"Enter lenght of side c in centimeters: ";
cin>>SideC;
SideB = sqrt(pow(SideC,2)-pow(SideA,2));
AngleA = asin(SideA/SideC) * 180 / PI;
AngleB = 90 - AngleA;
cout<<"Side b = "<<SideB<<" cm"<<endl
<<"Angle A = "<<AngleA<<" Degrees"<<endl
<<"Angle B = "<<AngleB<<" Degrees"<<endl
<<"Checks:"<<endl
<<"Total Angle sum = "<<AngleA+AngleB+AngleC<<" Degrees"<<endl
<<"Total lenght of triangle sides = "<<SideA+SideB+SideC<<" cm "<<endl;
break;
case 2:
cout<<"Enter lenght of side b in centimeters: ";
cin>>SideB;
cout<<"Enter lenght of side c in centimeters: ";
cin>>SideC;
SideA = sqrt(pow(SideC,2)-pow(SideB,2));
AngleA = acos(SideB/SideC) * 180 / PI;
AngleB = 90 - AngleA;
cout<<"Side a = "<<SideA<<" cm"<<endl
<<"Angle A = "<<AngleA<<" Degrees"<<endl
<<"Angle B = "<<AngleB<<" Degrees"<<endl
<<"Checks:"<<endl
<<"Total Angle sum = "<<AngleA+AngleB+AngleC<<" Degrees"<<endl
<<"Total lenght of triangle sides = "<<SideA+SideB+SideC<<" cm "<<endl;
break;
case 3:
cout<<"Enter lenght of side a in centimeters: ";
cin>>SideA;
cout<<"Enter lenght of side b in centimeters: ";
cin>>SideB;
SideC = sqrt(pow(SideA,2)+pow(SideB,2));
AngleA = atan(SideA/SideB) * 180 / PI;
AngleB = 90 - AngleA;
cout<<"Side c = "<<SideC<<" cm"<<endl
<<"Angle A = "<<AngleA<<" Degrees"<<endl
<<"Angle B = "<<AngleB<<" Degrees"<<endl
<<"Checks:"<<endl
<<"Total Angle sum = "<<AngleA+AngleB+AngleC<<" Degrees"<<endl
<<"Total lenght of triangle sides = "<<SideA+SideB+SideC<<" cm "<<endl;
break;
case 4:
cout<<"Enter Lenght of side c in centimeters: ";
cin>>SideC;
cout<<"Enter Angle A in degrees: ";
cin>>AngleA;
SideA = SideC*sin(AngleA*PI/180);
SideB = SideA*cos(AngleA*PI/180);
AngleB = 90 - AngleA;
cout<<"Side a = "<<SideA<<" cm"<<endl
<<"Side b = "<<SideB<<" cm"<<endl
<<"Angle B = "<<AngleB<<" Degrees"<<endl
<<"Checks:"<<endl
<<"Total Angle sum = "<<AngleA+AngleB+AngleC<<" Degrees"<<endl
<<"Total lenght of triangle sides = "<<SideA+SideB+SideC<<" cm "<<endl;
break;
case 5:
cout<<"Enter Lenght of side c in centimeters: ";
cin>>SideC;
cout<<"Enter Angle B in degrees: ";
cin>>AngleB;
SideA = SideC*cos(AngleB*PI/180);
SideB = SideC*sin(AngleB*PI/180);
AngleA = 90 - AngleB;
cout<<"Side a = "<<SideA<<" cm"<<endl
<<"Side b = "<<SideB<<" cm"<<endl
<<"Angle A = "<<AngleA<<" Degrees"<<endl
<<"Checks:"<<endl
<<"Total Angle sum = "<<AngleA+AngleB+AngleC<<" Degrees"<<endl
<<"Total lenght of triangle sides = "<<SideA+SideB+SideC<<" cm "<<endl;
break;
case 6:
cout<<"Enter Lenght of side a in centimeters: ";
cin>>SideA;
cout<<"Enter Angle B in degrees: ";
cin>>AngleB;
SideC = SideA/cos(AngleB*PI/180);
SideB = SideA*tan(AngleB*PI/180);
AngleA = 90 - AngleB;
cout<<"Side c = "<<SideC<<" cm"<<endl
<<"Side b = "<<SideB<<" cm"<<endl
<<"Angle A = "<<AngleA<<" Degrees"<<endl
<<"Checks:"<<endl
<<"Total Angle sum = "<<AngleA+AngleB+AngleC<<" Degrees"<<endl
<<"Total lenght of triangle sides = "<<SideA+SideB+SideC<<" cm "<<endl;
break;
case 7:
cout<<"Enter Lenght of side b in centimeters: ";
cin>>SideB;
cout<<"Enter Angle A in degrees: ";
cin>>AngleA;
SideC = SideB/cos(AngleA*PI/180);
SideA = SideB*tan(AngleA*PI/180);
AngleB = 90 - AngleA;
cout<<"Side c = "<<SideC<<" cm"<<endl
<<"Side b = "<<SideB<<" cm"<<endl
<<"Angle A = "<<AngleA<<" Degrees"<<endl
<<"Checks:"<<endl
<<"Total Angle sum = "<<AngleA+AngleB+AngleC<<" Degrees"<<endl
<<"Total lenght of triangle sides = "<<SideA+SideB+SideC<<" cm "<<endl;
break;
case 8:
cout<<"Enter Lenght of side a in centimeters: ";
cin>>SideA;
cout<<"Enter Angle A in degrees: ";
cin>>AngleA;
SideC = SideA/sin(AngleA*PI/180);
SideB = SideA/tan(AngleA*PI/180);
AngleB = 90 - AngleA;
cout<<"Side c = "<<SideC<<" cm"<<endl
<<"Side b = "<<SideB<<" cm"<<endl
<<"Angle B = "<<AngleB<<" Degrees"<<endl
<<"Checks:"<<endl
<<"Total Angle sum = "<<AngleA+AngleB+AngleC<<" Degrees"<<endl
<<"Total lenght of triangle sides = "<<SideA+SideB+SideC<<" cm "<<endl;
break;
case 9:
cout<<"Enter Lenght of side b in centimeters: ";
cin>>SideB;
cout<<"Enter Angle B in degrees: ";
cin>>AngleB;
SideC = SideB/sin(AngleB*PI/180);
SideA = SideB/tan(AngleB*PI/180);
AngleA = 90 - AngleB;
cout<<"Side c = "<<SideC<<" cm"<<endl
<<"Side a = "<<SideA<<" cm"<<endl
<<"Angle A = "<<AngleA<<" Degrees"<<endl
<<"Checks:"<<endl
<<"Total Angle sum = "<<AngleA+AngleB+AngleC<<" Degrees"<<endl
<<"Total lenght of triangle sides = "<<SideA+SideB+SideC<<" cm "<<endl;
break;
case 0:
return 0;
break;
default:
cout<<"You suck! Enter a command I understand!"<<endl;
break;
}
system("PAUSE");
system("CLS");
}
system("PAUSE");
return 0;
}
Og ja, jeg er newbie til C++.