-
Emergency!!! Help!!
I'm deperately trying not to fail out of my C++ class, I'm supposed to graduate
this semester. No matter what I do I can not get the toupper to work. The
program is a calculator, please see below. I know that I did not do it the
most efficient way, but it was the only way I could get it to work. Can you
please help me with the toupper part? I tried a bunch of different thing,
but this is how I started. Any suggestions you have for the rest, is of course,
appreciated.
Thanks! Shana
#include <iostream.h>
#include <cmath>
#include <ctype.h>
int main()
{
char operation;
float num1;
float num2;
float answer;
int toupper(int ch);
while (operation != 'Q')
{
cout << "Please enter the appropriate code for the function you would
like to perform." << endl << endl;
cout << " + : Addition" << endl;
cout << " - : Subtraction" << endl;
cout << " * : Multiplication" << endl;
cout << " / : Division" << endl;
cout << " E : Exponentiation" << endl;
cout << " S : Square Root" << endl;
cout << " Q : Quit" << endl << endl;
cin >> operation;
toupper (operation);
switch (operation)
{
case '+' : cout << "Please enter the first number." << endl;
cin >> num1;
cout << "Please enter the second number." << endl;
cin >> num2;
answer = num1 + num2;
cout << "The answer equals " << answer << "." << endl;
break;
case '-' : cout << "Please enter the first number." << endl;
cin >> num1;
cout << "Please enter the second number." << endl;
cin >> num2;
answer = num1 - num2;
cout << "The answer equals " << answer << "." << endl;
break;
case '*' : cout << "Please enter the first number." << endl;
cin >> num1;
cout << "Please enter the second number." << endl;
cin >> num2;
answer = num1 * num2;
cout << "The answer equals " << answer << "." << endl;
break;
case '/' : cout << "Please enter the first number." << endl;
cin >> num1;
cout << "Please enter the second number." << endl;
cin >> num2;
if (num2 == 0)
cout << "The divisor can not equal 0." << endl;
else
answer = num1 / num2;
cout << "The answer equals " << answer << "." << endl;
break;
case 'E' : cout << "Please enter the first number." << endl;
cin >> num1;
cout << "Please enter the second number." << endl;
cin >> num2;
answer = float(pow(num1, num2));
cout << "The answer equals " << answer << "." << endl;
break;
case 'S' : cout << "Please enter the number." << endl;
cin >> num1;
answer = float(sqrt(num1));
cout << "The answer equals " << answer << "." << endl;
break;
default : cout << operation << " is not an option. Please try again."
<< endl;
break;
case 'Q' : cout << "Exiting!" << endl;
}
}
return 0;
}
-
Re: Emergency!!! Help!!
uuughhh, I'm an idiot. I figured it out, finally.
operation = toupper (operation);
but, if you want to offer me suggetions on streamlining my program, that
would be great. I know there is a way to do a loop instead of the way I did
it, but I just couldn't get it to work.
Thanks, Shana
"Shana" <badelica@hotmail.com> wrote:
>
>I'm deperately trying not to fail out of my C++ class, I'm supposed to graduate
>this semester. No matter what I do I can not get the toupper to work. The
>program is a calculator, please see below. I know that I did not do it the
>most efficient way, but it was the only way I could get it to work. Can
you
>please help me with the toupper part? I tried a bunch of different thing,
>but this is how I started. Any suggestions you have for the rest, is of
course,
>appreciated.
>Thanks! Shana
>
>
>#include <iostream.h>
>#include <cmath>
>#include <ctype.h>
>
>int main()
>{
> char operation;
> float num1;
> float num2;
> float answer;
> int toupper(int ch);
>
> while (operation != 'Q')
> {
> cout << "Please enter the appropriate code for the function you would
>like to perform." << endl << endl;
> cout << " + : Addition" << endl;
> cout << " - : Subtraction" << endl;
> cout << " * : Multiplication" << endl;
> cout << " / : Division" << endl;
> cout << " E : Exponentiation" << endl;
> cout << " S : Square Root" << endl;
> cout << " Q : Quit" << endl << endl;
>
> cin >> operation;
> toupper (operation);
>
> switch (operation)
> {
> case '+' : cout << "Please enter the first number." << endl;
> cin >> num1;
> cout << "Please enter the second number." << endl;
> cin >> num2;
> answer = num1 + num2;
> cout << "The answer equals " << answer << "." << endl;
> break;
> case '-' : cout << "Please enter the first number." << endl;
> cin >> num1;
> cout << "Please enter the second number." << endl;
> cin >> num2;
> answer = num1 - num2;
> cout << "The answer equals " << answer << "." << endl;
> break;
> case '*' : cout << "Please enter the first number." << endl;
> cin >> num1;
> cout << "Please enter the second number." << endl;
> cin >> num2;
> answer = num1 * num2;
> cout << "The answer equals " << answer << "." << endl;
> break;
> case '/' : cout << "Please enter the first number." << endl;
> cin >> num1;
> cout << "Please enter the second number." << endl;
> cin >> num2;
> if (num2 == 0)
> cout << "The divisor can not equal 0." << endl;
> else
> answer = num1 / num2;
> cout << "The answer equals " << answer << "." << endl;
> break;
> case 'E' : cout << "Please enter the first number." << endl;
> cin >> num1;
> cout << "Please enter the second number." << endl;
> cin >> num2;
> answer = float(pow(num1, num2));
> cout << "The answer equals " << answer << "." << endl;
> break;
> case 'S' : cout << "Please enter the number." << endl;
> cin >> num1;
> answer = float(sqrt(num1));
> cout << "The answer equals " << answer << "." << endl;
> break;
> default : cout << operation << " is not an option. Please try again."
><< endl;
> break;
> case 'Q' : cout << "Exiting!" << endl;
> }
>
> }
>
> return 0;
>}
>
-
Re: Emergency!!! Help!!
"Shana" <badelica@hotmail.com> wrote:
>
>I'm deperately trying not to fail out of my C++ class, I'm supposed to graduate
>this semester. No matter what I do I can not get the toupper to work. The
>program is a calculator, please see below. I know that I did not do it the
>most efficient way, but it was the only way I could get it to work. Can
you
>please help me with the toupper part? I tried a bunch of different thing,
>but this is how I started. Any suggestions you have for the rest, is of
course,
>appreciated.
>Thanks! Shana
>
>
Stick to no hs or all hs, mixing can really mess things up!!
>#include <iostream.h>
>#include <cmath>
>#include <ctype.h>
>
>int main()
>{
> char operation;
> float num1;
> float num2;
> float answer;
> int toupper(int ch);
you do not need the headers for toupper; they are in
the standard .h's, I think you have this now...
initialize operation to be anything but 'Q' (it could be currently, at random!)
other than this, its fine...
>
> while (operation != 'Q')
> {
> cout << "Please enter the appropriate code for the function you would
>like to perform." << endl << endl;
> cout << " + : Addition" << endl;
> cout << " - : Subtraction" << endl;
> cout << " * : Multiplication" << endl;
> cout << " / : Division" << endl;
> cout << " E : Exponentiation" << endl;
> cout << " S : Square Root" << endl;
> cout << " Q : Quit" << endl << endl;
>
> cin >> operation;
> toupper (operation);
>
> switch (operation)
> {
> case '+' : cout << "Please enter the first number." << endl;
> cin >> num1;
> cout << "Please enter the second number." << endl;
> cin >> num2;
> answer = num1 + num2;
> cout << "The answer equals " << answer << "." << endl;
> break;
> case '-' : cout << "Please enter the first number." << endl;
> cin >> num1;
> cout << "Please enter the second number." << endl;
> cin >> num2;
> answer = num1 - num2;
> cout << "The answer equals " << answer << "." << endl;
> break;
> case '*' : cout << "Please enter the first number." << endl;
> cin >> num1;
> cout << "Please enter the second number." << endl;
> cin >> num2;
> answer = num1 * num2;
> cout << "The answer equals " << answer << "." << endl;
> break;
> case '/' : cout << "Please enter the first number." << endl;
> cin >> num1;
> cout << "Please enter the second number." << endl;
> cin >> num2;
> if (num2 == 0)
> cout << "The divisor can not equal 0." << endl;
> else
> answer = num1 / num2;
> cout << "The answer equals " << answer << "." << endl;
> break;
> case 'E' : cout << "Please enter the first number." << endl;
> cin >> num1;
> cout << "Please enter the second number." << endl;
> cin >> num2;
> answer = float(pow(num1, num2));
> cout << "The answer equals " << answer << "." << endl;
> break;
> case 'S' : cout << "Please enter the number." << endl;
> cin >> num1;
> answer = float(sqrt(num1));
> cout << "The answer equals " << answer << "." << endl;
> break;
> default : cout << operation << " is not an option. Please try again."
><< endl;
> break;
> case 'Q' : cout << "Exiting!" << endl;
> }
>
> }
>
> return 0;
>}
>
-
Re: Emergency!!! Help!!
Well, the best way to stream line it, is to unify all the inputting of
numbers. And the first step there is to break a common beginner's
habit --- even if switch is useful in your program, you shouldn't use it for
everything. If we pull the check for "Q" out of the switch statement, the
whole thing becomes much easier:
if (operation == 'Q')
cout << "Exiting!" << endl;
else
{
if (operation == 'S')
{
cout << "Please enter the number." << endl;
cin >> num1;
answer = float(sqrt(num1));
}
else
{
cout << "Please enter the first number." << endl;
cin >> num1;
cout << "Please enter the second number." << endl;
cin >> num2;
switch (operation)
{
case '+' : answer = num1 + num2; break;
case '-' : answer = num1 - num2; break;
case '*' : answer = num1 * num2; break;
case '/' :
if (num2 == 0)
cout << "The divisor can not equal 0." <<
endl;
else
answer = num1 / num2;
break;
case 'E' : answer = float(pow(num1, num2));
break;
}
} // if (=='S')
cout << "The answer equals " << answer << "." << endl;
} // if (=='Q')
--
Truth,
James Curran
www.NJTheater.com (Professional)
www.NovelTheory.com (Personal)
"Shana" <badelica@hotmail.com> wrote in message
news:3cc50e4a$1@10.1.10.29...
>
> I'm deperately trying not to fail out of my C++ class, I'm supposed to
graduate
> this semester. No matter what I do I can not get the toupper to work. The
> program is a calculator, please see below. I know that I did not do it the
> most efficient way, but it was the only way I could get it to work. Can
you
> please help me with the toupper part? I tried a bunch of different thing,
> but this is how I started. Any suggestions you have for the rest, is of
course,
> appreciated.
> Thanks! Shana
>
>
> #include <iostream.h>
> #include <cmath>
> #include <ctype.h>
>
> int main()
> {
> char operation;
> float num1;
> float num2;
> float answer;
> int toupper(int ch);
>
> while (operation != 'Q')
> {
> cout << "Please enter the appropriate code for the function you
would
> like to perform." << endl << endl;
> cout << " + : Addition" << endl;
> cout << " - : Subtraction" << endl;
> cout << " * : Multiplication" << endl;
> cout << " / : Division" << endl;
> cout << " E : Exponentiation" << endl;
> cout << " S : Square Root" << endl;
> cout << " Q : Quit" << endl << endl;
>
> cin >> operation;
> toupper (operation);
>
> switch (operation)
> {
> case '+' : cout << "Please enter the first number." << endl;
> cin >> num1;
> cout << "Please enter the second number." << endl;
> cin >> num2;
> answer = num1 + num2;
> cout << "The answer equals " << answer << "." << endl;
> break;
> case '-' : cout << "Please enter the first number." << endl;
> cin >> num1;
> cout << "Please enter the second number." << endl;
> cin >> num2;
> answer = num1 - num2;
> cout << "The answer equals " << answer << "." << endl;
> break;
> case '*' : cout << "Please enter the first number." << endl;
> cin >> num1;
> cout << "Please enter the second number." << endl;
> cin >> num2;
> answer = num1 * num2;
> cout << "The answer equals " << answer << "." << endl;
> break;
> case '/' : cout << "Please enter the first number." << endl;
> cin >> num1;
> cout << "Please enter the second number." << endl;
> cin >> num2;
> if (num2 == 0)
> cout << "The divisor can not equal 0." << endl;
> else
> answer = num1 / num2;
> cout << "The answer equals " << answer << "." << endl;
> break;
> case 'E' : cout << "Please enter the first number." << endl;
> cin >> num1;
> cout << "Please enter the second number." << endl;
> cin >> num2;
> answer = float(pow(num1, num2));
> cout << "The answer equals " << answer << "." << endl;
> break;
> case 'S' : cout << "Please enter the number." << endl;
> cin >> num1;
> answer = float(sqrt(num1));
> cout << "The answer equals " << answer << "." << endl;
> break;
> default : cout << operation << " is not an option. Please try
again."
> << endl;
> break;
> case 'Q' : cout << "Exiting!" << endl;
> }
>
> }
>
> return 0;
> }
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks