Temperature Converter

// Solved. Thank you everyone!
Last edited on
Look at lines 5 - 7. How many times do you think that loop is going to execute?
@MikeyBoy Ah, I see. The 0, right? So, if I want the loop to run infinitely times until user enters b (or something other than a), what do I do? (Sorry, I am new at c++!)

When I deleted the 0, the program still doesnt run
Last edited on
The 0 is not the issue.
It should look like this:

1
2
3
char userInput = 0;
while(userInput != 'b')
// if user inputs 'b', the loop will break. Exactly what you needed! 
@EssGeEich Ok, that's a start. The only problem is, when I hit a or b, it seems as though the program still works. Is there a problem with the loop?

** When I hit b, it goes to the else error. the program doesn't close!
Last edited on
Hi @sportstool,
this may help
you!


Eyenrique-MacBook-Pro:Desktop Eyenrique$ ./LoopEOF 
Enter number(ctrl+z to exit): 1
1 is odd
Enter number(ctrl+z to quit): 2
2 is even.
Enter number(ctrl+z to quit): 3
3 is odd
Enter number(ctrl+z to quit): 4
4 is even.
Enter number(ctrl+z to quit): 5
5 is odd
Enter number(ctrl+z to quit): ^Z <-- EOF command (ctrl+z Mac OS X)
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
//LoopEOF.cpp
//##

#include <iostream>
using std::cout;
using std::cin;
using std::endl;



bool isEven(int number);

int main(){

int number;

cout<<"Enter number(ctrl+z to exit): ";
cin>>number;

while(!cin.eof()){//while end-of-file character or sequence is NOT entered
        if(isEven(number))
                cout<<number<<" is even."<<endl;
        else{
                cout<<number<<" is odd"<<endl;
        }//end if-else

        cout<<"Enter number(ctrl+z to quit): ";
        cin>>number;
}//end while


return 0; //indicates success
}//end of main

bool isEven(int number){
        if(number%2==0)return true;

return false;
}//end function isEven 
Why have you deleted your original code? You've just ruined the value of this thread as a resource for other people to learn from.
Topic archived. No new replies allowed.