Looking for efficiency in my app
Hey all,
I'm still working on my calculator and I'm wondering if I can find an alternative to using if() statements within declared functions. Here's the code:
Code:
#include <iostream.h>
#include <stdlib.h>
void one(void)
{
int choice_1;
cout<<"Section one : Basic operations"<<endl<<endl;
cout<<"**********************************************************"<<endl;
}
void two(void)
{
int choice_2;
cout<<"Section two : Area configiration"<<endl<<endl;
cout<<"**********************************************************"<<endl;
}
void three(void)
{
int choice_3;
cout<<"Section three : Volumetrics"<<endl<<endl;
cout<<"**********************************************************"<<endl;
}
void four(void)
{
int choice_4;
cout<<"Section four : Trigonometry"<<endl<<endl;
cout<<"**********************************************************"<<endl;
}
void five(void)
{
int choice_5;
cout<<"Section five : Advanced algorithms and Calculus"<<endl<<endl;
cout<<"**********************************************************"<<endl;
}
void six(void)
{
int chocie_6;
cout<<"Section six : Unit conversion"<<endl<<endl;
cout<<"**********************************************************"<<endl;
}
int main()
{
int choice_main;
choice_main = 1 || 2 || 3 || 4 || 5 || 6;
cout<<"Advanced Mathematic calculator v.3.0.1 BETA"<<endl;
cout<<"Programmed by Dead Cell"<<endl;
cout<<"**********************************************************"<<endl;
cout<<"Please select a function from the list below:"<<endl<<endl;
cout<<"1 - Basic mathematical operations"<<endl<<"2 - Area configuration"<<endl<<"3 - Volumetrics"<<endl<<"4 - Trigonometrics"<<endl<<"5 - Advanced algorithms and calculus"<<endl<<"6 - Unit conversion"<<endl<<"7 - Exit Program"<<endl<<endl;
cin>>choice_main;
cout<<"**********************************************************"<<endl;
switch(choice_main)
{
case 1 : one();
break;
case 2 : two();
break;
case 3 : three();
break;
case 4 : four();
break;
case 5 : five();
break;
case 6 : six();
break;
case 7 : return 0;
break;
default: cout<<"Error, bad input, halting program..."<<endl<<endl;
}
system("PAUSE");
return 0;
}
Inside the functions before int main(), I want to declare case statements for each, but they don't seem to want to work with the functions I want to use.
Code:
void add(void)
{
blah blah
}
void subtract(void)
{
blargh bletch
}
//Hate to use comments. but begin section one
void one(void)
{
int choice;
cin>>choice;
switch(choice)
{
case 1 : add();
break;
case 2 : subtract();
break;
default : return 0;
}
}
I Keep getting an error pertaining to the declaration of the value '1' for a case statement. Is there any way around this, or am I going to have to resort back to if() statements?
Thanks again
(Oh, and yeah, I'm working on a calculator, so... don't laugh)