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
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??
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
Can you show us how have you implemented this do while loop?
Savage
i used
char rerun_choice = 'c'; - do
-
{
-
MY CODE
-
}
-
while (rerun_choice == 'y');
-
cout<<"run again type y"<<".\n";
-
cin>> rerun_choice;
-
-
Savage 1,764
Recognized Expert Top Contributor
i used
char rerun_choice = 'c'; - do
-
{
-
MY CODE
-
}
-
while (rerun_choice == 'y');
-
cout<<"run again type y"<<".\n";
-
cin>> rerun_choice;
-
-
Shouldn't that be inside the loop? - do{
-
YOUR CODE
-
-
cout<<"To run again type y"<<endl;
-
cin>> rerun_choice;
-
-
}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
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 ('==') -
if (operator == "+"){}
-
else if (operator == "/"){}
-
Your variable, "operator", is of type char. This means you might need to use a single quote rather than double quotes as follows: -
if (operator == '+')
-
cout<<"The Answer is: "<< x << "+" << y << "=" << x + y <<endl;
-
-
-
else if (operator == '-')
-
cout<<"The Answer is: "<< x << "-" << y << "=" << x - y <<endl;
-
-
-
else if (operator = '*')
-
cout<<"The Answer is: "<< x << "*" << y << "=" << x * y <<endl;
-
-
else if (operator = '/')
-
{
-
cout<<"The Answer is: "<< x << "/" << y << "=" << x / y <<endl;
-
cout<<"The Remainder is: "<< x << "%" << y << "=" << x % y <<endl;
-
}
-
-
else
-
cout<<"Bad operator input, try again..."<<endl;
-
Your variable, "operator", is of type char. This means you might need to use a single quote rather than double quotes as follows: -
if (operator == '+')
-
cout<<"The Answer is: "<< x << "+" << y << "=" << x + y <<endl;
-
-
-
else if (operator == '-')
-
cout<<"The Answer is: "<< x << "-" << y << "=" << x - y <<endl;
-
-
-
else if (operator = '*')
-
cout<<"The Answer is: "<< x << "*" << y << "=" << x * y <<endl;
-
-
else if (operator = '/')
-
{
-
cout<<"The Answer is: "<< x << "/" << y << "=" << x / y <<endl;
-
cout<<"The Remainder is: "<< x << "%" << y << "=" << x % y <<endl;
-
}
-
-
else
-
cout<<"Bad operator input, try again..."<<endl;
-
Yep, I missed that, sorry.
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?
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.
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?
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.
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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....
|
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!). ...
|
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...
|
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,...
| |
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...
|
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>
|
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
|
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....
|
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. ...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |