Basic Calculator
1. Enter two numbers
2. Addition
3. Multiplication
4. Subtraction
5. Division
6. Exit
Please enter a choice:1
1st number:
2nd number:
please enter a choice: 2
Addition:
1st number + 2nd number= 3rdnumber
please enter a choice: 3
Subtraction:
1st number - 2nd number= 3rdnumber
etc etc...
What is the c++ code for this problem?
I just copy/pasted this code. I does what you need and some more, just modify it as you wish:
#include %26lt;cstdlib%26gt;
#include %26lt;iostream%26gt;
using namespace std;
int main()
{
double num;
double num2;
char choice;
for (;;){
do {
cout%26lt;%26lt;"Welcome to thejoshcalculator. V1.5\n";
cout%26lt;%26lt;"Please choose an option by entering the number, press q to quit\n";
cout%26lt;%26lt;"1 - Addition\n";
cout%26lt;%26lt;"2 - Subtraction\n";
cout%26lt;%26lt;"3 - Division\n";
cout%26lt;%26lt;"4 - Multiplication\n";
cout%26lt;%26lt;"5 - Help\n";
cout%26lt;%26lt;"6 - About This Program\n";
cout%26lt;%26lt;"7 - Updates to this program\n";
cin%26gt;%26gt;choice;
} while ( choice %26lt; '1' || choice %26gt; '7' %26amp;%26amp; choice != 'q');
if (choice == 'q') break;
switch (choice) {
case '1':
cout%26lt;%26lt;"Please enter a number\n";
cin%26gt;%26gt;num;
cout%26lt;%26lt;"Another number to be added\n";
cin%26gt;%26gt;num2;
cout%26lt;%26lt;num + num2;
cout%26lt;%26lt;"\n";
break;
case '2':
cout%26lt;%26lt;"Please enter a number\n";
cin%26gt;%26gt;num;
cout%26lt;%26lt;"Another number to be subtracted\n";
cin%26gt;%26gt;num2;
cout%26lt;%26lt;num - num2;
cout%26lt;%26lt;"\n";
break;
case '3':
cout%26lt;%26lt;"Please enter a number\n";
cin%26gt;%26gt;num;
cout%26lt;%26lt;"Another one to be divided\n";
cin%26gt;%26gt;num2;
cout%26lt;%26lt;num / num2;
cout%26lt;%26lt;"\n";
break;
case '4':
cout%26lt;%26lt;"Please enter a number\n";
cin%26gt;%26gt;num;
cout%26lt;%26lt;"Another one to be multiplied\n";
cin%26gt;%26gt;num2;
cout%26lt;%26lt;num * num2;
cout%26lt;%26lt;"\n";
break;
case '5':
cout%26lt;%26lt;"This is a simple calculator made by me - Josh.\n";
cout%26lt;%26lt;"To select an option, type the number next to the option and press enter\n";
cout%26lt;%26lt;"E.G. for division, you would type 3 and press enter.\n";
cout%26lt;%26lt;"\n";
break;
case '6':
cout%26lt;%26lt;"thejoshcalculator, made by Joshua Griggs - Copyright 2007. :)\n";
cout%26lt;%26lt;"Feedback would be nice - joshieboy06@hotmail.com also, what programmes\n";
cout%26lt;%26lt;"do people need. Please give me ideas for programs. Bye!!\n";
cout%26lt;%26lt;"\n";
break;
case '7':
cout%26lt;%26lt;"Updates include: -double variable instead of int, so that decimals can be used.\n";
cout%26lt;%26lt;" -do while loop so that you can exit the program yourself\n";
cout%26lt;%26lt;"\n";
break;
default:
cout%26lt;%26lt;"That is not an option";
}
}
return 0;
}
Reply:main {
string name;
cout("enter your name");
cin("name");
cout("sorry ",name," I cannot do your homework for you");
}
end
- above is probably a mixmatch of c and c++ because I haven't done either in a while. but you basically do what is above, and do some math stuff where you put the variables back in.
have fun
Reply:Do not copy and paste the above code and submit it as your assignment, you will get caught and get a big ZERO, either code it yourself, or ask a freelancer from websites like http://getafreelnacer.com/ to code it for you
Reply:use a break statement is the switch block
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment