a do-while calculator

// 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;
result= num_a () num_b;
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.



  • I'm not quite sure what you're wanting to do in terms of the two egg shells, but maybe this will help.

    #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
    case '-' : // do something
    case '/' : // do something
    case '*' : // do something
    case 'q' : cout << "the end";
    default : cout << choice << " is not a valid operator";

    } while(tolower(choice)) != 'q');


  • Thank you so much.
  • no worries. :)
  • In the quest of expanding the calculating power of my calculator I added a switch and another do-while loop.
    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')

    Cout>> "enter the power."<<endl;
    Case '1':
    cout>> "enter the base."
    Cin>> (a)
    cout>> results <<endl;

    case '2':
    cout<< "enter the base."
    Cin>> (a)
    results = a*a
    cout<< results <<endl;


    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>

    using namespace std;

    int main()
    int a, b, c, d, i, r;


    c = b - 1;
    d = a - 1;
    i = d * d + d + d + 1;

    if (b <=2);

    r = i;

    cout<< r ;

    while (b<=2);

    if (b>2);
    do {

    r= b*i;

    cout<< r;

    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


    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



    Any feedback on the algorithm or the for loop will be apprichiate.

    thanks in advance,
  • This post has been deleted.
  • This post has been deleted.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!