473,403 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Please help with debug

1
Hi, I'm having a problem with what seems to be simple math with a section of my code, I isolated the problem area so that it can be compiled on its own and I'll place it below. It should be extremely basic and I feel odd asking a question on such a small code (26 lines >_<) but I cant figure out why it isn't calculating correctly.

What I mean this section of code to do is:
1. print basic mode selected- endline
2. print please add number to be transformed- endline
3. input to double "number"
4. double transformed = (((number - 150) /100) +1)
5. print some more text, print number, print transformed.
6. if y then starts over.

but when I compile it, it doesnt seem to be calculating transformed correctly. For example ill input 4000, and the print will be:
"The transformed number for 4000 is:
-0.5"
it should have done (((4000-150) /100) +1) which would normally = 39.5
why am I getting -0.5?
help please :) , this is my code:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. double number;
  6. double transformed = (((number - 150) /100)+1);
  7. string mode_select;
  8. string rebasic;
  9.  
  10. int main() {  
  11.            basicagain:
  12.            cout << "Basic mode selected" << endl << endl;
  13.            cout << "Please enter number to be transformed." << endl;
  14.            cin >> number;  
  15.            cout << endl << "The transformed number for " << number << " is:" << endl;
  16.            cout << transformed << endl;
  17.            cout << "Calculate another? (Y/N)" << endl;
  18.            cin >> rebasic;
  19.  
  20.                if (rebasic == "y" || rebasic == "Y") {
  21.                   goto basicagain;
  22.                }
  23. }
I'm a beginner, only have been coding for about 2 weeks so any other tips would be helpful. Thanks again.
Jul 24 '07 #1
1 1105
JosAH
11,448 Expert 8TB
Hi, I'm having a problem with what seems to be simple math with a section of my code, I isolated the problem area so that it can be compiled on its own and I'll place it below. It should be extremely basic and I feel odd asking a question on such a small code (26 lines >_<) but I cant figure out why it isn't calculating correctly.

What I mean this section of code to do is:
1. print basic mode selected- endline
2. print please add number to be transformed- endline
3. input to double "number"
4. double transformed = (((number - 150) /100) +1)
5. print some more text, print number, print transformed.
6. if y then starts over.

but when I compile it, it doesnt seem to be calculating transformed correctly. For example ill input 4000, and the print will be:
"The transformed number for 4000 is:
-0.5"
it should have done (((4000-150) /100) +1) which would normally = 39.5
why am I getting -0.5?
help please :) , this is my code:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. double number;
  6. double transformed = (((number - 150) /100)+1);
  7. string mode_select;
  8. string rebasic;
  9.  
  10. int main() {  
  11.            basicagain:
  12.            cout << "Basic mode selected" << endl << endl;
  13.            cout << "Please enter number to be transformed." << endl;
  14.            cin >> number;  
  15.            cout << endl << "The transformed number for " << number << " is:" << endl;
  16.            cout << transformed << endl;
  17.            cout << "Calculate another? (Y/N)" << endl;
  18.            cin >> rebasic;
  19.  
  20.                if (rebasic == "y" || rebasic == "Y") {
  21.                   goto basicagain;
  22.                }
  23. }
I'm a beginner, only have been coding for about 2 weeks so any other tips would be helpful. Thanks again.
It's not that a 'formula' is getting applied automagically; computer languages are
far more stupid than that. You have to do this: (I simply copied/pasted your work)

Expand|Select|Wrap|Line Numbers
  1. // deleted a bit ...
  2.  
  3. double number;
  4. double transformed;
  5. string mode_select;
  6. string rebasic;
  7.  
  8. int main() {  
  9.            basicagain:
  10.            cout << "Basic mode selected" << endl << endl;
  11.            cout << "Please enter number to be transformed." << endl;
  12.            cin >> number;  
  13.            cout << endl << "The transformed number for " << number << " is:" << endl;
  14.            // the value of 'number' is known at this place so calculate now:
  15.            transformed = (((number - 150) /100)+1);
  16.            cout << transformed << endl;
  17.            cout << "Calculate another? (Y/N)" << endl;
  18.            cin >> rebasic;
  19.  
  20.                if (rebasic == "y" || rebasic == "Y") {
  21.                   goto basicagain;
  22.                }
  23. }
kind regards,

Jos

the initial value of 'number' was 0.0 (zero) that explains why 'transformed' was -0.5
Jul 24 '07 #2

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

Similar topics

4
by: Lloyd Sheen | last post by:
So MS where is the error that is reported on last line, says 1 failed. No indication as to what failed. VS 2003, (reinstalled more times than should have been). ------ Build started: Project:...
3
by: Mahmood Ahmad | last post by:
Hello, I have written a program that reads three types of records, validates them acording to certain requirements and writes the valid records into a binary file. The invalid records are...
4
by: pshindle | last post by:
DB2 Team - I just downloaded and unzipped the new Fixpack 9 for DB2 ESE V8 for Windows (FP9_WR21350_ESE.exe). I then burned the unzipped Fixpack files to a CD. I proceded to install this...
10
by: darren | last post by:
hi iam righting aprogram that creates its own desktop shotcut and a want to add a command line switch so i want to have a string like this "C:\Documents and Settings\Darren\My Documents\Visual...
2
by: Claire Streb | last post by:
Dear Microsoft, You make some great products, really, but I have a request: Please stop taking away functionality from your users. 1) In Visual Studio 6, we had two output folders, Debug and...
4
by: Pete H | last post by:
I would like to have my new C++ projects start out with two configurations, UnicodeDebug and UnicodeRelease, instead of the standard Debug and Release configurations that Visual Studio always...
3
by: Kris van der Mast | last post by:
Hi, I've created a little site for my sports club. In the root folder there are pages that are viewable by every anonymous user but at a certain subfolder my administration pages should be...
4
by: Warren Sirota | last post by:
Hi, Please let me know if I am interpreting this correctly. I've done a little testing of the difference between passing parameters byVal and byRef, and the results were slightly non-intuitive,...
36
by: Cap'n Ahab | last post by:
I have used VB3 - VB6, so learning all this OO stuff is reasonably new to me (although I looked at Java a few years ago). Anyway, I thought I would write a small class to begin with, with a...
61
by: warint | last post by:
My lecturer gave us an assignment. He has a very "mature" way of teaching in that he doesn't care whether people show up, whether they do the assignments, or whether they copy other people's work....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.