Hi,
I want to create a loop inside a calculator which would ask the user to input the operation and the numbers again and would keep on pestering the user till they get it right.
I used the word assistance in the title because the word help is taboo.
/* Future Note for Myself: This version includes square roots and also exponents.
Also, this series no longer uses numbers for operations. Numbers for operation have been replaced
with a character constant. It still uses 'if statements'. I am still working on a way to create
a loop to make the user continually input data if it is incorrect. Next version: Work on including trignometric formulas in the calculator. */
#include <cstdlib>
#include <iostream>
#include <string>
#include <math.h>
usingnamespace std;
int main()
{
double first;//teh first number
char operation;//operation that is inputted and then later used in if statement
double second; // tehe second number
double result; // the first result which is displayed
cout << "Calc v3 "<< endl;
cout<< "If you want to find a square root or use exponents";
cout<< " please enter random stuff until the first part of the program is executed"<<endl;
cout<< ""<<endl;
cout<<""<<endl;
cout<< " Enter the expression you wish to calculate"<<endl;
cout<< ""<<endl;
cout<< " For example: '1*2'"<<endl;
cin >> first;
cin >> operation;
cin >> second;
if (operation == '+') result = first + second;
if (operation == '-') result = first - second;
if (operation == '*') result = first * second;
if (operation == '/') result = first / second;
cout<< " The answer is "<< result<<endl;
cout << ""<<endl;
cout << ""<<endl;
cout << ""<<endl;
cout<< "If you wish to find a square root or use exponents."<<endl;
cout<< "If not, now is the time to press the 'X' at the top right corner of this window"<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
longdouble second_input;
longint second_result;
longdouble exponent;
string second_choice;
cout<< " Please enter the number"<<endl;
cin >> second_input;
cout<< " Enter exp to repeatedly multiply the number"<<endl;
cout<< " Enter sqrt to find the square root of the number"<<endl;
cin >> second_choice;
cout<< " Enter how many times the number should be multiplied"<<endl;
cin >> exponent;
if (second_choice=="exp") result= pow(second_input,exponent);
if (second_choice=="sqrt") result= sqrt(second_input);
return 0;
}
Well i guess i didn't need to post the whole code. i didn't understand how the while and for loops worked. can someone help me? sorry i meant to type assist.
If you're trying to be a smartass with "help is taboo", it's really working, because I can really feel the smartass vibe coming out of it.
There's nothing taboo about "help". What's supposed to be taboo is homework, and whether you say help or assist, I (and probably, plenty of other people) can tell that this is homework. It's a standard and common assignment. Despite the fact that you aren't supposed to post homework on this forum, we still get a lot of it and for some reason, we still help people. I'm too much of a conformist to break convention so I'm still going to help you.
Now what you need to tell us (since we're already going out of our way by helping you with homework (or am I not supposed to say that either?)) is what's going wrong.
im sorry, i sounded like a jackass but im just pissed that i asked on another forum and i got insulted for typing the word help. and this manual that i have sucks rocks.
well i kind of get the idea of using do-for loops but im gonna try to see how to get it to work for my program.
btw this isn't homework. i worked on version 1 of this cuz i was bored during last summer. i just stumbled upon it when i saw a channel called AntiRTFM on youtube.