EOF won't terminate???

So I have my latest assignment almost complete but when I enter the EOF the program kicks into an endless loop? I have found that I can tend to get a little "curly brace crazy" so I'm not sure if thats the issue I'm running into or if it's something else. I have the EOF command in lines 46,57,93. Here's the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//  Temperature Conversions Algorithm

// 1. Declare function prototypes
// 2. Input and calculate variables in main function
// 3. Construct "do_while" loop for main function
   // 1. Include "EOF" termination
// 4. Welcome user to program 
// 5. Prompt user to enter value in Farenheit

// Loop
   //  Calculate the value in Farenheit and return in Celsius
   //  Prompt user to enter value in Celsius
   //  Calculate the value in Celsius and retun in Farenheit
   

//  End Algorithm for Temperature Conversions

#include <iostream>
#include <iomanip>

using namespace std;

// Function Prototypes
double farenConvert (double f, double c);
double celConvert (double c, double f);  
                                 
// Define Variables
double f, c;
char retry = 'Y' || 'y';

     int main()
       {
           
           cout  << "Welcome to the Temperature Converter.\n"  <<  endl  << endl;
           
           
           do  
           {
// Farenheit to Celsius conversion
            
           cout  <<  "Please enter a number in Farenheit that you would "   <<   
           "like to convert to Celsius:  "  <<  endl  <<  endl;
           { 
                 
           cin  >>  f;
           if (!cin.eof()) 
       
           cout << fixed << showpoint << setprecision(1);
           cout  <<  "The answer is:  "  <<  celConvert (f ,c)  <<    endl  <<  endl;
           
// Celsius to Farenheit conversion
           
           cout  <<  "Please enter a number in Celsius that you would "  <<  
           "like to convert to Farenheit:   "  <<  endl  <<  endl;
           
           cin  >>  c;
           if (!cin.eof())
           cout  <<  "The answer is:  "  <<  farenConvert (f , c)  <<  endl  <<  endl;
           
           
           cout  <<  "Would you like to do another conversion?  (Y/N)"  <<  endl;
           cin  >>  retry;
           
                                
           
           } 
           
           
           
  //  Celsius Conversion Function
    
    double celConvert (double f, double c);
    {
        double celConvert;
        
        celConvert = ((f - 32) / 180.00) * 100.00;
        
        
        
        }
        
        
// Fahrenheit Conversion Function

        double farenConvert (double f, double c);
        {  // line 92
               double farenConvert;
               
               farenConvert = 32 + c * (180.00 / 100.00);
               
              
               
               } while (!cin.eof());
           
            
}          
       
       system ("pause");
       return 0;
       
}
      

Your do doesn't have a while.

You've declared the functions celConvert and farenConvert inside of main. They are seperate, and if you have { stuff } right after you don't need the semicolon.
So I need to move the
 while 
on line 93 to line 66? Also, is their an easy way to remember the
 do while 
structuring?
Easy way to remember the structure is:
1
2
3
4
do
{
    /*code*/
}while(/*condition*/);
Last edited on
Thanks to the both of you. I got my original issue worked out but now those updates have caused my temperature conversions to all return a "1. $" (or other random symbol). Any idea what could be causing this? The function definitions are lines 70-88.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//  Temperature Conversions Algorithm

// 1. Declare function prototypes
// 2. Input and calculate variables in main function
// 3. Construct "do_while" loop for main function
   // 1. Include "EOF" termination
// 4. Welcome user to program 
// 5. Prompt user to enter value in Farenheit

// Loop
   //  Calculate the value in Farenheit and return in Celsius
   //  Prompt user to enter value in Celsius
   //  Calculate the value in Celsius and retun in Farenheit
   

//  End Algorithm for Temperature Conversions

#include <iostream>
#include <iomanip>

using namespace std;

// Function Prototypes
double farenConvert (double f, double c);
double celConvert (double c, double f);  
                                 
// Define Variables
double f, c;
char retry = 'Y' || 'y';

     int main()
{
           
           cout  << "Welcome to the Temperature Converter.\n"  <<  endl  << endl;
           
           
           do  
           {
// Farenheit to Celsius conversion
            
           cout  <<  "Please enter a number in Farenheit that you would "   <<   
           "like to convert to Celsius:  "  <<  endl  <<  endl;
            
                 
           cin  >>  f;
           if (!cin.eof()) 
       
           cout << fixed << showpoint << setprecision(2);
           cout  <<  "The answer is:  "  <<  celConvert (f ,c)  <<    endl  <<  endl;
           
// Celsius to Farenheit conversion
           
           cout  <<  "Please enter a number in Celsius that you would "  <<  
           "like to convert to Farenheit:   "  <<  endl  <<  endl;
           
           cin  >>  c;
           if (!cin.eof())
           cout  <<  "The answer is:  "  <<  farenConvert (f , c)  <<  endl  <<  endl;
           
           
           cout  <<  "Would you like to do another conversion?  (Y/N)"  <<  endl;
           cin  >>  retry;
           
           } while (!cin.eof());
           
              system ("pause");
              return 0;   
}    
           
  //  Celsius Conversion Function
    
    double celConvert (double f, double c)
    {
        double celConvert;
        
        celConvert = ((f - 32) / 180.00) * 100.00;
        
        }
             
// Farenheit Conversion Function

        double farenConvert (double f, double c)
        {  
               double farenConvert;
               
               farenConvert = 32 + c * (180.00 / 100.00);
              
               } 
           
      

      


First off, how come your celConvert has a c parameter and farenConvert has an f parameter? These are unnecessary since the function is returning this value.

This leads to the answer, your functions aren't returning anything. I don't see how your compiler didn't catch this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
    double celConvert (double f)
    {
        double celValue;
        
        celValue = ((f - 32) / 180.00) * 100.00;
        
        return celValue;
              
        }
             
// Farenheit Conversion Function

        double farenConvert (double c)
        {  
               double farenValue;
               
               farenValue = 32 + c * (180.00 / 100.00);

               return farenValue;
              
               } 


Also, I changed the variable names in these functions to be less ambiguous. Make sure to change the function calls in main as well.
Last edited on
Topic archived. No new replies allowed.