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

help using EOF to stop the loop

I am having trouble figuring out how to stop from the loop using EOF. I need to use a while loop in main and use EOF to stop it. Can anyone guide me.
This is part of the program I was asked to do:
Expand|Select|Wrap|Line Numbers
  1. cout << "Type EOF if you wish to end\n";
  2.     while (counter != 'EOF') 
  3.     {
  4.         read_scores (test1, test2, test3);
  5.         grade = calc_grade (test1, test1, test3);
  6.         display_grade (grade, test1, test2, test3, i);
  7.         i++;
  8.  
  9.     }
  10.  
i am aware that my loop is endless... plz help
Apr 16 '07 #1
5 9270
sicarie
4,677 Expert Mod 4TB
You use 'EOF' in single quotes, which turns it into the "end of file" character, not the letters E, O, and F which would be input by the user. (Aside of the fact that you never cin anything...)

I'd recommend changing that to a sentinel value such as -1, or something else that the user is not likely to input on accident.
Apr 16 '07 #2
ok here is a revised version, please tell me what you think
Expand|Select|Wrap|Line Numbers
  1. cout << "Enter any number to continue: <EOF> to stop.\n";
  2.     while (cin >> x)
  3.         {
  4.         read_scores (test1, test2, test3);
  5.         grade = calc_grade (test1, test1, test3);
  6.         display_grade (grade, test1, test2, test3, i);
  7.         i++;
  8.         }
  9.     return 0;
btw, why do i get no error messages when i compile the whole program, but when i build the program, i get this message:
Linking...
proj51.obj : error LNK2001: unresolved external symbol "char __cdecl calc_grade(int,int,int)" (?calc_grade@@YADHHH@Z)
Debug/prog5.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Apr 16 '07 #3
sicarie
4,677 Expert Mod 4TB
ok here is a revised version, please tell me what you think
Expand|Select|Wrap|Line Numbers
  1. cout << "Enter any number to continue: <EOF> to stop.\n";
  2.     while (cin >> x)
  3.         {
  4.         read_scores (test1, test2, test3);
  5.         grade = calc_grade (test1, test1, test3);
  6.         display_grade (grade, test1, test2, test3, i);
  7.         i++;
  8.         }
  9.     return 0;
btw, why do i get no error messages when i compile the whole program, but when i build the program, i get this message:
Linking...
proj51.obj : error LNK2001: unresolved external symbol "char __cdecl calc_grade(int,int,int)" (?calc_grade@@YADHHH@Z)
Debug/prog5.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Ok, so let me ask you, with this bit of code:
Expand|Select|Wrap|Line Numbers
  1. while (cin >> x) {
  2.  
when is that going to exit the while loop? Granted, if the user types in 'EOF' it will, but it will error out, and I'm not sure that's what you want. I'd recommend putting something like a boolean test to set after all 3 of your methods complete properly.

Other than that, let's take a look at your error:
proj51.obj : error LNK2001: unresolved external symbol "char __cdecl calc_grade(int,int,int)" (?calc_grade@@YADHHH@Z)
Debug/prog5.exe : fatal error LNK1120: 1 unresolved externals
Okay, so those together say you have an 'unresolved external' at ' char __cdecl calc_grade(int, int, int)'. With that, how and where is your calc_grade() method defined? Did you provide the implementation for that method? Do the signatures match (three ints passed to it with a return type of int)?

After having looked at your program, I'd like to ask, why do you have a 'read_scores()' method that is already passed 3 variables? Shouldn't the read_scores() method ... well ... read the scores in? And unless you use an array as a return type, those can only be done one at a time, which means the internal logic of that bit of code is a bit skewed. Maybe something like this would be better?

while boolean_stillAddingGrades {
read grade in
add to sum
increment num_of_grades_read
check to see if boolean_stillAddingGrades needs to be changed
}
calculate average
display grades
Apr 16 '07 #4
weaknessforcats
9,208 Expert Mod 8TB
This code:

while (counter != 'EOF')


should be:

while (counter != EOF)

The EOF character is a CTRL+Z indicating end of all input.

Use it after all your data lines have been entered and then enter CTRL+Z followed by the enter key to get the EOF character into the buffer.
Apr 16 '07 #5
sicarie
4,677 Expert Mod 4TB
This code:

while (counter != 'EOF')


should be:

while (counter != EOF)

The EOF character is a CTRL+Z indicating end of all input.

Use it after all your data lines have been entered and then enter CTRL+Z followed by the enter key to get the EOF character into the buffer.
What OS/Compiler are you using? I tried that on an FC6/GCC box and could not get it to work (though I'm probably doing something wrong...).

::edit:: when I say "I can't get it to work" I mean I can't get it to exit the input loop and still execute code after that (some sort of print or calculation of the input variables) - Ctrl+Z and then Enter will background the program, but will not terminate the input on the while loop for me (I didn't think there was a way to input the EOF char from the keyboard without setting it up specially).
Apr 16 '07 #6

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

Similar topics

7
by: Simon Harvey | last post by:
Hi everyone, I need to make a service that monitors a directory for changes in the files contained within it. I have two questions: 1. I'm going to be using a FileSystemWatcher object to do...
3
by: Keith Mills | last post by:
Hello, please find attached a basic outline of what I am attempting to accomplish... basically I want to create a number of THREADS (which I can do fine), but I then need a method for them to be...
6
by: ransoma22 | last post by:
I developing an application that receive SMS from a connected GSM handphone, e.g Siemens M55, Nokia 6230,etc through the data cable. The application(VB.NET) will receive the SMS automatically,...
2
by: Chris Smith | last post by:
Howdy, I'm a college student and for one of we are writing programs to numerically compute the parameters of antenna arrays. I decided to use Python to code up my programs. Up to now I haven't...
0
by: south622 | last post by:
I'm taking a beginning Java course and I'm stuck in week eight of a nine week course. If anyone could help me I would greatly appreciate it. This assignment was due yesterday and each day I go past...
2
by: alxasa | last post by:
Hi, I have a setInterval which executes its command every 10 seconds in a infinite loop. I've got something real basic like: var processes=0; function startme(){ if(stopthisloop>1)
5
by: Claude Grecea | last post by:
If anyone could help, I would greatly appreciated. I am using a "For Loop" and thru each complete iteration I would like it to stop and ask for user input, but I would not like to use a...
41
by: c | last post by:
Hi every one, Me and my Cousin were talking about C and C#, I love C and he loves C#..and were talking C is ...blah blah...C# is Blah Blah ...etc and then we decided to write a program that...
0
by: LanaR | last post by:
Hello, one sql statement is causing severe performance issue. The problem occurs only in UDB environment, the same statemnt on the mainframe is running fine. I have an explain output from the sql....
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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
jinu1996
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...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.