GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-Mar-2009, 09:05
slyslick slyslick is offline
New Member
 
Join Date: Feb 2009
Posts: 4
slyslick is on a distinguished road

Looping problem


Hello everyone. I received some greatly appreciated help here before and now I am stuck and have another issue that I'm hoping someone will be able to help me with. I'm writing a simple integer calculator that supports addition, subtraction, multiplication, modulus, and division. I have to implement this by defining a class. The program is suppose to 1. request and accept a number, 2. apply the stored operation (of which the first is addition and after it should be whatever the user enters), 3. request and accept the next operation. When the operation entered is '=', the result should be printed and the accumulator reset, when '!' is entered as the operator, the same should happen except the program should now terminate.

Here is a sample run of what I'm trying to accomplish

Code:
Welcome to the calculator ------ Input: 10 Operation: * Input: 2 Operation + Input: -5 Operation: = Result: 15 ------ Input: 12 Operation: / Input: 0 **Division by zero - start over ------ Input: 12 Operation: > **Invalid operation - ignored Operation: / Input: 5 Operation: = Result: 2 ------ Input: 10 Operation: % Input: 6 Operation: * Input: 3 Operation: ! Result: 12 ------ Calculator Off!


The issue I am having is when I run the program, the while loop is not continuing as it should and exits right away without op being '='. I have attached the files with the code I have so far because I didn't want to make this post any longer than it already is.

Any help would be greatly appreciated. Also feel free to make any comments on anything else I could improve on.
Attached Files
File Type: txt calculator.cpp.txt (1.2 KB, 7 views)
File Type: txt calculator.h.txt (582 Bytes, 3 views)
File Type: txt Main.cpp.txt (1.3 KB, 5 views)
  #2  
Old 11-Mar-2009, 13:30
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 713
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: Looping problem


The very first thing I saw was
CPP / C++ / C Code:
//while (!(op = '!')); //while op is not '!' keep going

// The above should use == instead of = like
//while (!(op == '!'));  which could be simplified to
//while( op != '!' ); ,but then you need to eliminate the ; so:

while( op != '!' )
{
  // do stuff here
}
  #3  
Old 24-Mar-2009, 18:33
slyslick slyslick is offline
New Member
 
Join Date: Feb 2009
Posts: 4
slyslick is on a distinguished road

Re: Looping problem


I know it has been a long time but I just want to say thank you for your help
 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache Web Server newbie problem niss3 Apache Web Server Forum 1 13-Apr-2009 19:38
Looping problem: Wont ask user to use program again NeXus C Programming Language 1 10-Nov-2006 01:47
Problem with looping. rina C Programming Language 2 04-Oct-2005 07:37
a significant problem after installing Xp mohammad Computer Software Forum - Windows 10 09-Aug-2005 08:03

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 22:59.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.