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

MY program keeps telling i have an error why?

i am writng a program, what is my error i cant seem to figure out it.

i got and error when an if-else statement in my code

here is the if-else statement what the error, i cant figure it out.

Expand|Select|Wrap|Line Numbers
  1.  
  2. if(numberOfBagsToPassenger<2)
  3.             {
  4.                 totalCharges=numberOfBagsToPassenger % 100;
  5.                 outFile << totalCharges;
  6.             }
  7.             else
  8.             {
  9.                 totalCharges=numberOfBagsToPassenger % 100;
  10.                 outFile << "nocharge";
  11.             }
  12.  
Oct 25 '08 #1
3 1335
donbock
2,426 Expert 2GB
What error did you get?
Also, please translate the line number you see in your error to correspond to the line numbers we see in the code block you posted.
Oct 25 '08 #2
What error did you get?
Also, please translate the line number you see in your error to correspond to the line numbers we see in the code block you posted.
the error i got says that warning C4700: uninitialized local variable 'numberofBagsToPassenger' used.
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.             if(numberOfBagsToPassenger<2) //This line wher error coming from.
  4.             {
  5.                 totalCharges=numberOfBagsToPassenger%100;
  6.                 outFile << "ADDITIONALCHARGES:" << totalCharges<< endl;
  7.             }
  8.             else
  9.             {
  10.                 totalCharges=numberOfBagsToPassenger%100;
  11.                 outFile << "nocharge" << endl;
  12.             }
  13.  
Oct 25 '08 #3
donbock
2,426 Expert 2GB
"Uninitialized variable" means that you're reading a variable before any value has been written into it. The warning message furthermore tells you that the variable in question is 'numberofBagsToPassenger'.

This begs the question ... are you sure your program assigned a value to 'numberofBagsToPassenger' before checking to see if it is less than 2?

The C Standard does not require compilers to detect uninitialized variables. You're fortunate that your compiler goes the extra mile to warn you of this mistake.
Oct 25 '08 #4

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

Similar topics

2
by: Brent W. Hughes | last post by:
I'm just starting to learn pygame. I write what I think is just about the simplest program that should display a window and then quit. #----------------------------------------------- import sys...
22
by: edgrsprj | last post by:
PROPOSED EARTHQUAKE FORECASTING COMPUTER PROGRAM DEVELOPMENT EFFORT Posted July 11, 2005 My main earthquake forecasting Web page is: http://www.freewebz.com/eq-forecasting/Data.html ...
2
by: bbxrider | last post by:
for win2k adv server/iis5.0 trying to run an external program from my asp routine that has multiple parameters, see following set shell = server.createobject("wscript.shell") shell.Run...
29
by: keredil | last post by:
Hi, Will the memory allocated by malloc get released when program exits? I guess it will since when the program exits, the OS will free all the memory (global, stack, heap) used by this...
4
by: Kristof Despiere | last post by:
Suppose you have one domain, filled with a couple of users. What needs to be done now is I need to start a windows application from a webform by pressing a button on the webform (for example). ...
8
by: koorb | last post by:
I am starting a program from a module with the Sub main procedure and I want it to display two forms for the program's interface, but when I run the program both forms just open and then program...
16
by: Martin Joergensen | last post by:
Hi, I wanted to try something which I think is a very good exercise... I read in data from the keyboard and store them in a structure. There's a pointer called "data_pointer" which I use to...
9
by: ehabaziz2001 | last post by:
I am facing that error message with no idea WHY the reason ? "Abnormal program termination" E:\programs\c_lang\iti01\tc201\ch06\ownarr01o01 Enter a number : 25 More numbers (y/n)? y...
10
by: charmeda103 | last post by:
My program keeps getting me and error and i dont why here is the error message error C2061: syntax error: identifier 'infile' error C2660: 'ReadDate' : function does not take 6 arguments...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.