473,513 Members | 3,777 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Equation printing program

67 New Member
So i have a question on how i should start doing this... pretty new at c++

i have to ask the user for an integer, an operator, and then another integer to give an answer. But i also have to show the whole equation. I want to try to use loops to do this.
Sep 19 '07
63 5314
socondc22
67 New Member
Im using a do while loop to try to rerun my program at the end so that itll ask me to type y in order to rerun... everytime i type y and hit enter it exits the program... any ideas??
Sep 21 '07 #51
Savage
1,764 Recognized Expert Top Contributor
Im using a do while loop to try to rerun my program at the end so that itll ask me to type y in order to rerun... everytime i type y and hit enter it exits the program... any ideas??
Can you show us how have you implemented this do while loop?

Savage
Sep 21 '07 #52
socondc22
67 New Member
Can you show us how have you implemented this do while loop?

Savage

i used

char rerun_choice = 'c';

Expand|Select|Wrap|Line Numbers
  1. do
  2.             {
  3.               MY CODE
  4.             }
  5.                while (rerun_choice == 'y');
  6.                cout<<"run again type y"<<".\n";
  7.                cin>> rerun_choice;
  8.  
  9.  
Sep 21 '07 #53
Savage
1,764 Recognized Expert Top Contributor
i used

char rerun_choice = 'c';

Expand|Select|Wrap|Line Numbers
  1. do
  2.             {
  3.               MY CODE
  4.             }
  5.                while (rerun_choice == 'y');
  6.                cout<<"run again type y"<<".\n";
  7.                cin>> rerun_choice;
  8.  
  9.  
Shouldn't that be inside the loop?

Expand|Select|Wrap|Line Numbers
  1. do{
  2.         YOUR CODE
  3.  
  4.          cout<<"To run again type y"<<endl;
  5.          cin>> rerun_choice;
  6.  
  7. }while(rerun_choice=='Y')
Also you should convert user input to upper letters(what if user inputed y?)
You can use toupper(),defined in ctype.h

Savage
Sep 21 '07 #54
ilikepython
844 Recognized Expert Contributor
it says expected identifier before ")" token for this part...

else if ((operator) = "/")
You shouldn't need the second set of parenthesis and you need the double equal sign ('==')

Expand|Select|Wrap|Line Numbers
  1. if (operator == "+"){}
  2. else if (operator == "/"){}
  3.  
Sep 21 '07 #55
archonmagnus
113 New Member
Your variable, "operator", is of type char. This means you might need to use a single quote rather than double quotes as follows:

Expand|Select|Wrap|Line Numbers
  1. if (operator == '+')
  2.     cout<<"The Answer is: "<< x << "+" << y << "=" << x + y <<endl;
  3.  
  4.  
  5. else if (operator == '-')
  6.     cout<<"The Answer is: "<< x << "-" << y << "=" << x - y <<endl;
  7.  
  8.  
  9. else if (operator = '*')
  10.     cout<<"The Answer is: "<< x << "*" << y << "=" << x * y <<endl;
  11.  
  12. else if (operator = '/')
  13. {
  14.     cout<<"The Answer is: "<< x << "/" << y << "=" << x / y <<endl;
  15.     cout<<"The Remainder is: "<< x << "%" << y << "=" << x % y <<endl;
  16. }
  17.  
  18. else
  19.     cout<<"Bad operator input, try again..."<<endl;
  20.  
Sep 21 '07 #56
ilikepython
844 Recognized Expert Contributor
Your variable, "operator", is of type char. This means you might need to use a single quote rather than double quotes as follows:

Expand|Select|Wrap|Line Numbers
  1. if (operator == '+')
  2.     cout<<"The Answer is: "<< x << "+" << y << "=" << x + y <<endl;
  3.  
  4.  
  5. else if (operator == '-')
  6.     cout<<"The Answer is: "<< x << "-" << y << "=" << x - y <<endl;
  7.  
  8.  
  9. else if (operator = '*')
  10.     cout<<"The Answer is: "<< x << "*" << y << "=" << x * y <<endl;
  11.  
  12. else if (operator = '/')
  13. {
  14.     cout<<"The Answer is: "<< x << "/" << y << "=" << x / y <<endl;
  15.     cout<<"The Remainder is: "<< x << "%" << y << "=" << x % y <<endl;
  16. }
  17.  
  18. else
  19.     cout<<"Bad operator input, try again..."<<endl;
  20.  
Yep, I missed that, sorry.
Sep 21 '07 #57
sicarie
4,677 Recognized Expert Moderator Specialist
Any ideas on what i should do because i need to try to get it done for tomorrow?
After you made the assignment, what error messages did you get?
Sep 21 '07 #58
sicarie
4,677 Recognized Expert Moderator Specialist
After you made the assignment, what error messages did you get?

And this is an example of why we ask people to not double post.

Socondc22 - please read our Posting Guidelines and follow them in the future (not double-posting). Thanks.
Sep 21 '07 #59
sicarie
4,677 Recognized Expert Moderator Specialist
instead of asking to continue its just rerunning the program... im not sure if i have everything placed right...
And this is another example of why you shouldn't double (triple) post. Did you take Savage's advice in your other thread and put the prompt inside the do-while loop?
Sep 21 '07 #60
Ganon11
3,652 Recognized Expert Specialist
AGH!

USE A DIFFERENT NAME FOR YOUR CHAR VARIABLE.

Sorry, I can't believe no one's caught this yet. You can't use operator as the name of your char variable, because operator== is a function call for classes. Your compiler thinks you are calling the function operator== in every if statement, and then complains at the fact that there's no object, no parentheses, and no argument. Change the name to oper and see if it works.
Sep 21 '07 #61
sicarie
4,677 Recognized Expert Moderator Specialist
AGH!

USE A DIFFERENT NAME FOR YOUR CHAR VARIABLE.

Sorry, I can't believe no one's caught this yet. You can't use operator as the name of your char variable, because operator== is a function call for classes. Your compiler thinks you are calling the function operator== in every if statement, and then complains at the fact that there's no object, no parentheses, and no argument. Change the name to oper and see if it works.
It was caught (or at least different) in his other thread. There are three floating around now, I haven't gotten around to cleaning them all up.
Sep 21 '07 #62
Ganon11
3,652 Recognized Expert Specialist
I'm not sure if this is the 3rd or 4th time you've asked for help on this question, but before you proceed any further, could you take a good look at our Posting Guidelines, specifically the portion entitled Do Not Double Post your Questions.
Sep 21 '07 #63
ilikepython
844 Recognized Expert Contributor
AGH!

USE A DIFFERENT NAME FOR YOUR CHAR VARIABLE.

Sorry, I can't believe no one's caught this yet. You can't use operator as the name of your char variable, because operator== is a function call for classes. Your compiler thinks you are calling the function operator== in every if statement, and then complains at the fact that there's no object, no parentheses, and no argument. Change the name to oper and see if it works.
Yes AGH!!!
I thought about that the name might be the problem at least 5 times but I couldn't figure out why so I always ignored it.

P.S. The O/P made it really confusing with double posting.
Sep 22 '07 #64

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1620
by: Russell Blau | last post by:
This is not really a Python question, but it does relate to a Python program I'm working on, so this seems like as good a place as any to ask for suggestions ... I'm working on a GUI application that lets the user enter an alegbraic equation and displays a nicely-formatted representation of the same equation (and then maybe does other stuff...
20
8666
by: Brian Kazian | last post by:
Here's my problem, and hopefully someone can help me figure out if there is a good way to do this. I am writing a program that allows the user to enter an equation in a text field using pre-existing variables. They then enter numerical values for these variables, or can tell the program to randomize the values used within a certain bounds....
2
1443
by: Michael MacDonald | last post by:
I have written a simple program that calculates a running $ total. This program uses a checkbox to acknowledge that that version of the ticket is desired and it checks the Qty box to see how many tickets are desired. Based upon the checkbox being checked and the number of tickets desired directly affects the running grand total (of course!). ...
6
14828
by: Trev17 | last post by:
Hello, I am new to C++ and i have tried for several hours to make a program my teacher has given me as a lab. Here is the Lab question: the roots of the quadratic equation ax^2 + bx + c = 0, a cannot equal 0 are given by the following formula -b + or - square root of (b^2 - 4ac) / 2a. If b^2 - 4ac = 0 then equation has a single root. if...
11
3851
by: shanazzle | last post by:
so I've just begun learning python for a school course. I have to write a simple program that finds the first derivative of the equation Y= Ax^4 + Bx^3 + Cx^2 + Dx + E so far i can have the user input the variables, but one of the requirements is to have the program show the orignial formula with the inputed variables. because x is not defined,...
1
1501
by: kjcheste | last post by:
I'm trying to have C++ solve an equation I have set up. The equation is: angle = (1/16)*(pow(LS,2) + LS*sqrt(pow(LS,2) + pow(16,2) - 1) - 1); where LS is a number from -1 to 1 by increasing it by 0.0001 I have angle and LS defined as double, when I run this program it tells me that the angle is equal to -1, -0, or 0 no matter what LS...
2
2601
by: ioannoual | last post by:
Hi...I 'am new in C and I want a program that solves a quadratic equation!! I try something by my self to write some code about that but I want you to help me writing a new one that will work!! #include <stdio.h> #include <stdlib.h> #include <math.h>
1
2368
by: bbench123 | last post by:
Make a program that will ask for values of a quadratic equation (ax2+bx+c). the program must determine the roots of the equation using the quadratic equation determinants to distinguish if the roots are imaginary no. or real no. quadratic eq. x= -b sqrt b2-4ac/2a
1
2985
by: candacefaye1 | last post by:
1. write a C++ program to decide if the coefficients of a quadratic equation have real roots. The three choices will be to write the message “zero divide” when A is zero, write the message “no real roots” if the discriminant is negative and find the two roots when there is no error condition. DO NOT FIND THE ROOT IF THERE IS AN ERROR CONDITION....
0
7397
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7563
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7125
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5102
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4757
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3252
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3239
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.