// Hello, I'm trying to develop a calculator because I think it would be the best program-type to learn and expanding programming skills. I am able to compile a workable console-calculator that reads the source once then exits. I don't want this, so,, I am trying to add a do-while loop to this application.
my-self developed theory (as-if all of these are supposed to work) is a do-while loop is like making an egg with two shells. lets call these shells the main-shell and the switch-shell because this is how I'm trying to apply this loop. My sources looks something like
int main()
{
cout<< "Press + , -. * or /"<<endl;
cout<< "Press Q to quit"<<endl;
cin>> (ch);
do if (ch!= 'q')
switch (ch)
{
case 'all possible !q's':
cout<<"enter numbers"<endl;
cin>>num_a>>num_b;
result= num_a () num_b;
cout<<result;
break;
}
while (ch=='q')
return 0;
}
If someone can expond on my understanding I will appreciate it and if i solve my problem I'll post Thanks in advance.
Newb1001
Comments
[code]
...
#include // or math.h
#include // or ctype.h
...
int main(void) {
...
char choice;
do {
cout << "Enter operator (+, -, /, *): ";
cin >> choice; while(cin.get() != '
'){}
switch(tolower(choice)) {
case '+' : // do something
break;
case '-' : // do something
break;
case '/' : // do something
break;
case '*' : // do something
break;
case 'q' : cout << "the end";
break;
default : cout << choice << " is not a valid operator";
}
} while(tolower(choice)) != 'q');
...
}[/code]
HTH
What I have added to my code, which basically looks like this
Count>> "Press E for Exponents and M for basic math"<<endl;
Cin>> (ch1);
Switch (ch != 'M')
do
{
Cout>> "enter the power."<<endl;
Case '1':
cout>> "enter the base."
Cin>> (a)
results=a
cout>> results <<endl;
case '2':
cout<< "enter the base."
Cin>> (a)
results = a*a
cout<< results <<endl;
...etc...}
As you can see the aforementioned code makes for a lot of scripting. What I need help with is understanding the for loop or figuring out a simple mathmatical algorithm that will work to process exponential equasions.
I am having difficulty understanding the for loop entirely.
as for the algorithm goes I have started working on one
#include <iostream>
#include
using namespace std;
int main()
{
int a, b, c, d, i, r;
cout<<"Talk."<<endl;
cin>>a>>b;
c = b - 1;
d = a - 1;
i = d * d + d + d + 1;
if (b <=2);
do
{
r = i;
cout<< r ;
break;
}
while (b<=2);
if (b>2);
do {
r= b*i;
cout<< r;
break;
}
while (b>2);
return 0;
}
what this algorithm says is basically 2 square plus 2 and 3 = 3 squared
so if a = 3 and b= 2
then a-1 = d and d * d + d + d + 1= 3 squared
But when I try to equate a to the power of 4, i get incorrect values using
a(d*d+d+d+1)
because the aformentioned formula works with cubes and I understand that my variable b and c are not functioning in the code other than b working with the switch. I wrote c premptively and I need to figure out how to make b inneract with my formula in a way for my results to equate the desired power (if that makes sense).
also my results display the value of i then r instead of just r
like 4 cubed displays
1664
etc.
Any feedback on the algorithm or the for loop will be apprichiate.
thanks in advance,
Newb1001