how to terminate a program?

first of all learning c++ on your own ain't easy at all. second, i'm sitting here going crazy and not knowing how to terminate a program by using a letter. here's part of my program.

"Enter Y/y to convert a telephone number form letters to digits.
Enter any other letter to terminate the program.
y"

the first 2 lines are easy to do. but i'm thinking way too much on how to terminate the program if the user does not type in the letter y or Y.i'm at the point where i just give up and the sad part about is that it's only just the beginning! i know i'm suppose to create a boolean and a while loop for this and that's as far as i can get. i go back to my book and read on what their trying to explain but i just don't get it. i'm a slow learner BTW (sigh). to the ppl that are reading this go ahead and laugh. i just can't get this program stuff through my head and i get all stressed about it which makes it even worse.
try using an if statement.
like:
if(input != "y" || input != "Y")
{
return EXIT_SUCCESS;
}
i had something very similar to that but instead of the if i used the while loop. i was getting all stressed to know if that was correct or not. i need to use while and switch in my program assignment.
I also did learn C/C++/C# on my own and I agree that it's not easy. But since I started in C, C++ made more sense right away when I started learning it.

Your problem concerns with generic programming algorithm. So do not give up C++ just because of that because that algorithm is very common in most languages. I have been at where you are right now, and trust me, nobody laughed at me before and I do not intend to do so right now.

As to the problem itself, here is a hint:
1
2
3
4
5
//Initialize input -either hard code or prompt user for value
while(input == 'Y' || input == 'y'){
    //Convert telephone numbers.
    //Prompt user for input's value.
}

I do not know what kind of algorithm is required for converting telephone numbers but as far as the validation goes, I believe that's just what you need.
@katielynnsdad:
This statement is always true, for any input:
 
(input != "y" || input != "Y")


I suggest using tolower, so that you don't need to check both 'Y' and 'y':
1
2
3
if (std::tolower(input) != 'y') // True for all except 'Y' and 'y'
// or
while (std::tolower(input) == 'y') // True for 'Y' and 'y' 
sry for the late reply. but thanks for the help. i really appreciate it. its just that i have so many other issues outside of schoolwork thats affecting me and my work, and not having any experience with c++ thrown into the equation makes it much worse. last night i decided to drop the assignment and wait until later on tonight. i'm going to head on over to my friends dads house and have him help me with this program since he has years of experience with c++. he has helped me in the past, and was very helpful. i didn't want to call him yesterday since it was easter and didn't want to be rude and ask for help. also my teacher today gave us an extra 2 days to finish it since some people had problems with the assignment and others just coming back from spring break. so i lucked out right there. BTW i'm a slow learner, but once i understand on what i'm learning, everything just clicks and i develop other ways to do my work; whereas other ppl learn it in an instant but doesn't get any further than that.


sry for the really big post. i'd just ought to let you guys know a little bit of my background and why i was stressing out on a simple algorithm.
Topic archived. No new replies allowed.