Question

Can sombody tell me what wrong for this code to work?? It is c++ btw. thanks!...

Can sombody tell me what wrong for this code to work?? It is c++ btw. thanks!

#include <iostream>

#include <string>


using namespace std;

double op1;
double op2;
string ADD;
string SUBTRACT;
string MULTIPLY;
string DIVIDE;
string selection;
string multiply;
string divide;
string add;
string subtract;

string "*";
string "+";
string "-";
string "/";


int main() {

do {
cout << "--------WELCOME TO THE CALCULATOR----------" << endl;

cout << "Enter your first operand: ";
cin >> op1;

cout << "Enter your second operand: ";
cin >> op2;
cout << endl;

cout << "Operations are:" << endl;

cout << "For addition enter: ADD or +" <<endl;
cout << "For subtraction enter: SUBTRACT or -" << endl;
cout << "For MUTLIPLACTION enter: MULTIPLY or *" << endl;
cout << "For DIVISION enter: DIVIDE or /" << endl;

cout << "Enter your selection: ";
cin >> selection;

switch(selection) {

case MULTIPLY:
{
answer1 = op1 * op2;
}
cout << "Your product is: " << answer1 << endl;
break;

case DIVIDE:
{
answer2= op1 / op2;
}
cout << "Your product is: " << answer2 << endl;
break;

case ADD:
{
answer3= op1 + op2;
}
cout << "Your product is: " << answer3 << endl;
break;

case SUBTRACT:
{
answer4= op1 - op2;
}
cout << "Your product is: " << answer4 << endl;
break;

case Multiply:
{
answer5 = op1 * op2;
}
cout << "Your product is: " << answer5 << endl;
break;

case divide:
{
answer6= op1 / op2;
}
cout << "Your product is: " << answer6 << endl;
break;

case add:
{
answer7= op1 + op2;
}
cout << "Your product is: " << answer7 << endl;
break;

case subtract:
{
answer8= op1 - op2;
}
cout << "Your product is: " << answer8 << endl;
break;

case '*' :
{
answer9 = op1 * op2;
}
cout << "Your product is: " << answer9 << endl;
break;

case '/' :
{
answer10= op1 / op2;
}
cout << "Your product is: " << answer10 << endl;
break;

case '+' :
{
answer11= op1 + op2;
}
cout << "Your product is: " << answer11 << endl;
break;

case subtract:
{
answer12= op1 - op2;
}
cout << "Your product is: " << answer12 << endl;
break;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//note:- if you have any query regarding this then comment below. please upvote. In your code, you are doing lots of mistakes. I rectify all and correct that.

#include <iostream>
#include <string>

using namespace std;
double op1;
double op2;
double answer;
int selection;

int main() {

char ch;
do {
cout << "--------WELCOME TO THE CALCULATOR----------" << endl;

cout << "Enter your first operand: ";
cin >> op1;

cout << "Enter your second operand: ";
cin >> op2;
cout << endl;

cout << "Operations are:" << endl;

cout << "For addition enter: 1" <<endl;
cout << "For subtraction enter: 2" << endl;
cout << "For MUTLIPLACTION enter: 3" << endl;
cout << "For DIVISION enter: 4" << endl;

cout << "Enter your selection: ";
cin >> selection;

switch(selection)
{

case 3:
{
answer = op1 * op2;
cout << "Your product is: " << answer << endl;
break;
}


case 4:
{
answer= op1 / op2;
cout << "Your product is: " << answer << endl;
break;
}


case 1:
{
answer= op1 + op2;
cout << "Your product is: " << answer << endl;
break;
}

case 2:
{
answer= op1 - op2;
cout << "Your product is: " << answer << endl;
break;
}


default:
{
cout<<"Invalid Choice";
break;
}


}
cout<<"Do you want to calculate more(press y for continue.)";

cin>>ch;
}
while(ch=='y');
}

WELCOME TO THE CALCULATOR Enter your first operand 2 Enter your second operand: 3 perations are: For addition enter: 1 For subtraction enter: 2 For MUTLIPLACTION enter: 3 For DIUISION enter 4 Enter your selection: 1 our product is5 Do you want to calculate more press y for continue.>y WELCOME TO THE CALCULATOR Enter your first operand5 Enter your second operand perations are: For addition enter: 1 For subtraction enter: 2 For MUTLIPLACTION enter: 3 For DIUISION enter 4 Enter your selection: 2 our product is -2 Do you want to calculate more press y for continue.>

Add a comment
Know the answer?
Add Answer to:
Can sombody tell me what wrong for this code to work?? It is c++ btw. thanks!...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Can you tell me what is wrong and fix this code. Thanks #include <iostream> #include <string>...

    Can you tell me what is wrong and fix this code. Thanks #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; //function void displaymenu1(); int main ( int argc, char** argv ) { string filename; string character; string enter; int menu1=4; char repeat; // = 'Y' / 'N'; string fname; string fName; string lname; string Lname; string number; string Number; string ch; string Displayall; string line; string search; string found;    string document[1000][6];    ifstream infile; char s[1000];...

  • SEE THE Q3 for actual question, The first Two are Q1 and Q2 answers . Q1...

    SEE THE Q3 for actual question, The first Two are Q1 and Q2 answers . Q1 #include<iostream> using namespace std; // add function that add two numbers void add(){    int num1,num2;    cout << "Enter two numbers "<< endl;    cout << "First :";    cin >> num1;    cout << "Second :";    cin >>num2;    int result=num1+num2;    cout << "The sum of " << num1 << " and "<< num2 <<" is = "<< result;   ...

  • #include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int...

    #include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int num1, num2, result; while(ch == 'Y'){ cout << "Enter first number: "; cin >> num1; while(1){//for handling invalid inputs if(cin.fail()){ cin.clear();//reseting the buffer cin.ignore(numeric_limits<streamsize>::max(),'\n');//empty the buffer cout<<"You have entered wrong input"<<endl; cout << "Enter first number: "; cin >> num1; } if(!cin.fail()) break; } cout << "Enter second number: "; cin >> num2; while(1){ if(cin.fail()){ cin.clear(); cin.ignore(numeric_limits<streamsize>::max(),'\n'); cout<<"You have entered wrong input"<<endl; cout <<...

  • Write a C++ program which performs +, -, *, / and $ on hexadecimal operands. The...

    Write a C++ program which performs +, -, *, / and $ on hexadecimal operands. The maximum length of any operand or a solution is 40 digits. The input will be in the following format: Op1 op op2 = There is no space between operands and operator. Note 5/2 = quotient 2, remainder 1 2$3 = 8 The output should be of the form 2*3=6. Read date from a file. TEST DATA (input.txt): AAAA+BBF= BFD+2DE= 100*AA= 100$5= 100/F= 10000000000000-1= AAAAABBBBBCCCCCDDDDDEEEEEFFFFF-ABCDEF0123456789ABCDEF=...

  • I'm kind of new to programming, and I am having trouble figuring out why my program...

    I'm kind of new to programming, and I am having trouble figuring out why my program isn't running. Below is the code that I wrote for practice. I will comment where it says the error is. So the error that I'm getting is "error: no match for 'operator>>' (operand types are 'std::istream {aka std::basic_istream<char>}' ". I'm not sure why I'm getting this because I added the library <iostream> at the top. Thank you. Code: #include <iostream> using namespace std; class...

  • 1. in this programe i want add some products to be shown after choosing choise (...

    1. in this programe i want add some products to be shown after choosing choise ( show all products ) before i add any products. let say 10 products have added to the program then when the user choose (show all products ) all the 10 products appear and the user going to choose one and that one must has its own name, price,and quantity after that the quantity will be reduce. 2. allow the user to buy products. ===========================================================...

  • The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried t...

    The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried to divide the code in 3 parts (Patient.h, Patient.cpp and Main.cpp), but it is giving me errors. Patient.h #ifndef PATIENT_H #define PATIENT_H #include <string> #include "Patient.cpp" using namespace std; class Patient{ private : string firstname; string lastname; string location; static int cnt; int id; public : Patient(string, string, string);...

  • C++ Banks offer various types of accounts, such as savings, checking, certificate of deposits, and money...

    C++ Banks offer various types of accounts, such as savings, checking, certificate of deposits, and money market, to attract customers as well as meet their specific needs. Two of the most commonly used accounts are savings and checking. Each of these accounts has various options. For example, you may have a savings account that requires no minimum balance but has a lower interest rate. Similarly, you may have a checking account that limits the number of checks you may write....

  • Help me to fix this code in C language. This code converts infix expressions to postfix and then evaluate the expression...

    Help me to fix this code in C language. This code converts infix expressions to postfix and then evaluate the expression. Right now, it works with single digits. I need to modify it so that it can evaluate expressions with also 2 digits, example: (60+82)%72. Additionally I need to display an error when the parenthesis don't match like (89+8(. I have muted some line that would print the postfix expression with a space like: 22 8 + when the input...

  • c++ programming : everything is done, except when you enter ("a" ) in "F" option ,...

    c++ programming : everything is done, except when you enter ("a" ) in "F" option , it does not work. here is the program. #include <iostream> #include <string> #include <bits/stdc++.h> #include <iomanip> #include <fstream> using namespace std; #define MAX 1000 class Inventory { private: long itemId; string itemName; int numberOfItems; double buyingPrice; double sellingPrice; double storageFees; public: void setItemId(long id) { itemId = id; } long getItemId() { return itemId; } void setItemName(string name) { itemName = name; } string...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT