Write a C ++ program that allows the user to enter two numericvalues. Then let t
ID: 3608724 • Letter: W
Question
Write a C ++ program that allows the user to enter two numericvalues. Then let the user enter a single character as the desiredoperation: a for add s for subtract m for multiply and d fordivision. Perform the arithmetic operation that the user selectsand display the results.this is what i have come up with so far:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
double valx, valy;
char a, s, m, d;
cout<<"Please enter a numericalvalue"<<endl;
cin>>valx;
cout<<"Please enter another numericalvalue"<<endl;
cin>>valy;
cout<<"Please enter an arithmeticoperation: a (addition) s (subtraction) m (multiplication) d (division)"<<endl;
cin>>a, s, m, d;
if(a == a)
cout<<valx<<"+"<<valy<<"="<<valx +valy<<endl;
else
if (s == s)
cout<<valx<<"-"<<valy<<"="<<valx-valy<<endl;
else
if (m == m)
cout<<valx<<"*"<<valy<<"="<<valx *valy<<endl;
else
if (d == d)
cout<<valx<<"/"<<valy<<"="<<valx /valy<<endl;
else
cout<<"Invalid entry please try again."<<endl;
getch();
}
this is the error/warning i receive
arithmeticchoice.cpp(21) : warning C4700: uninitialized localvariable 's' used
arithmeticchoice.cpp(24) : warning C4700: uninitialized localvariable 'm' used
arithmeticchoice.cpp(27) : warning C4700: uninitialized localvariable 'd' used
i am new to c++ and just started to learn this language. couldsomeone please tell me what i am doing incorrectly? I will ratewell if you do. Thanks
Explanation / Answer
please rate - thanks changes are in red-you were real close #include #include using namespace std; int main() { double valx, valy; char op; coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.