473,322 Members | 1,501 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,322 software developers and data experts.

Errors from a Program I wrote

I am writing a program for class and I keep getting error messages that I am not declaring variables that are clearly declared. I only get this message when I write a program that requires a input from the user. Below is my code that I wrote and the error message can someone tell me what am I doing wrong? I am using Visual Basic and C++.

Thanks in advance.....

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main ()
  5. {
  6.     const float TAXRATE = 0.06;
  7.     float totalCost, total_discount, taxDue, amountDue;
  8.     float cost;
  9.     float num_items;
  10.     float discountRate;
  11.  
  12.     totalCost = num_items * cost;
  13.     total_discount = totalCost - discountRate * totalCost;
  14.     taxDue = total_discount * TAXRATE;
  15.     amountDue = total_discount + taxDue;
  16.  
  17.     cout<<"Please enter the Cost of all Items: \n";
  18.     cin >> cost;
  19.     cout<<"Please enter the Numbr of Items: \n";
  20.     cin >> num_items;
  21.     cout<<"Please enter the Discounted Rate: \n";
  22.     cin >> discountRate;
  23.  
  24.     cout<<"The Total Cost is: "<<totalCost<<" .\n";
  25.     cout<<"The Tax Due: "<<taxDue<<" .\n";
  26.     cout<<"The Amount Due: "<<amountDue<<" \n";
  27.  
  28.     return 0;
  29. }
  30.  
  31.  
1>------ Rebuild All started: Project: Q10p175, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'Q10p175', configuration 'Debug|Win32'
1>Compiling...
1>Q10p175.cpp
1>c:\documents and settings\dj000034880\desktop\computer science\lab assignment 2\q10p175\q10p175\q10p175.cpp(8) : warning C4305: 'initializing' : truncation from 'double' to 'const float'
1>c:\documents and settings\dj000034880\desktop\computer science\lab assignment 2\q10p175\q10p175\q10p175.cpp(14) : warning C4700: uninitialized local variable 'num_items' used
1>c:\documents and settings\dj000034880\desktop\computer science\lab assignment 2\q10p175\q10p175\q10p175.cpp(14) : warning C4700: uninitialized local variable 'cost' used
1>c:\documents and settings\dj000034880\desktop\computer science\lab assignment 2\q10p175\q10p175\q10p175.cpp(15) : warning C4700: uninitialized local variable 'discountRate' used
1>Compiling manifest to resources...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>Linking...
1>LINK : C:\Documents and Settings\dj000034880\Desktop\Computer Science\Lab Assignment 2\Q10p175\Debug\Q10p175.exe not found or not built by the last incremental link; performing full link
1>Embedding manifest...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>Build log was saved at "file://c:\Documents and Settings\dj000034880\Desktop\Computer Science\Lab Assignment 2\Q10p175\Q10p175\Debug\BuildLog.htm"
1>Q10p175 - 0 error(s), 4 warning(s)
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
Oct 1 '08 #1
2 1498
archonmagnus
113 100+
It's not that your variables are not declared, it's that they are undefined. When you declare a variable, it will not automatically have a useful value. In fact, it's almost always garbage values that are left at a particular memory address.

To give you an example of what you are doing, compile this code:
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main (void)
  6. {
  7.     // Declare two values, but do not initialize them
  8.     int foo, bar;
  9.  
  10.     // Bar is uninitialized so foo will be a garbage value
  11.     foo = bar + 65;
  12.  
  13.     cout<<foo;
  14.  
  15.     return;
  16. }
  17.  
If you were to initialize "bar" to, say, zero, "foo" would then have a value of 65. But, as the current code stands, you would simply have an erroneous value of "foo".

In the case of your program, you are performing operations with uninitialized values. Prompt the user for input first (giving the variables useful values), then perform the operations with those values.
Oct 1 '08 #2
uh, I see what you mean now. So all I have to do is move the total cost, etc to follow the code asking for the input, that I should be ok?

That is what I did and I didnt have any problems.

Thank you so much for your help with this matter....
Oct 1 '08 #3

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

Similar topics

6
by: Aaron | last post by:
I would like to write a program that finds all asp.net errors in iis logs? what characteristics should i look for? (a line in the log that has the error?) what about sql errors? Thanks in...
0
by: SM | last post by:
Hi, While linking orbix C++ application, we get a lot of linking errors. Few errors are pasted below. If someone could tell us which are the libraries that need to be added, it would be of help....
2
by: Kavitha Rao | last post by:
Hi, I am getting the following errors while trying to run this snippet in Microsoft Visual C++.Can't seem to print the crc value stored. /* +++Date last modified: 05-Jul-1997 */ /* Crc - 32...
2
by: Z.K. | last post by:
I am new to the Visual Studio.net platform and I was trying to compile a program that I downloaded from the net and keep getting a ton of errors. It looks like it can't find some of the libraries:...
7
by: sophie | last post by:
Hi everyone, I've got an exam in c++ in two days and one of the past questions is as follows. Identify 6 syntax and 2 possible runtime errors in this code: class demo { private:
5
by: Eric_Dexter | last post by:
I was trying to add this to my project but I must be missing some includes or there is a serius error somewhere Anthra Norell wrote:
4
by: daivdh | last post by:
I recently tried to download and install a Gadget called "Piano" which would put a piano keyboard on the screen. It downloaded and installed okay. When I dragged the keyboard from the sidebar onto...
6
by: aureao4 | last post by:
I'm new to Java and programming. I'm trying to code a payroll program and continue getting errors. The program worked last week, this week I have to add set, get and a class. I've written the class...
14
by: Martin Wells | last post by:
When I have errors in a program, whether they be compiler errors, linker errors, or if the program crashes when running, I have a list of things I check for initially. If I get an error for...
5
by: tcby16 | last post by:
I am supposed to use two classes to perform one of three math operations depending on the user's choice. Use if statements to allow the user to choose which math operation to execute. So I created...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.