Write a program that reads characters from the keyboard until
a $ is typed.
Have the program count the number of periods.
Report the total at the end of the program.
char Typedletters, $;
cout << "Start typing some characters: ";
cin >> Typedletters;
case 1: if(char Typedletters != $)
cout << "Type some more characters in.";
case 2: if(char Typedletters == $)
cout << "You entered a $$$ Money sign!";
This is the output I am aiming for.
Please enter your characters: asdfasdfasdf
Continue to enter more characters: Morecharacters
Continue to enter more characters: asdf$
You entered a $ sign!
Press any key to continue...
I would like the program to ask the first time for characters,
if a $ is NOT entered, I wish for the program to ask for characters to be entered again.
But when the character $ is entered, the program should stop.
1>------ Build started: Project: Unit 3 Module Program 1, Configuration: Debug Win32 ------
1>Unit 3 Module 1.cpp
1>l:\visual studio 2008\projects\unit 3 module program 1\unit 3 module program 1\unit 3 module 1.cpp(19) : error C2143: syntax error : missing ',' before '!='
1>l:\visual studio 2008\projects\unit 3 module program 1\unit 3 module program 1\unit 3 module 1.cpp(21) : error C2143: syntax error : missing ',' before '=='
1>l:\visual studio 2008\projects\unit 3 module program 1\unit 3 module program 1\unit 3 module 1.cpp(25) : error C2043: illegal break
1>Build log was saved at "file://l:\Visual Studio 2008\Projects\Unit 3 Module Program 1\Unit 3 Module Program 1\Debug\BuildLog.htm"
1>Unit 3 Module Program 1 - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
in the first if statement i set up another if statement inside of it which says if the character variable Typedletters does not equal '$'(when comparing character variables always use ' ' around the character that is being looked for if it is not already declared a variable) and if Typedletters does equal '.' than add a number to the counter nump which is then cout at the end showing how many times the character '.' is typed in any further questions ask me
i could have used a while loop but i thought a goto would be easier for a novice programmer like BloodMoney to understand im sorry that you cannot appreciate my teaching but if you dont like it help him yourself dont insult my work
ok goto is a nice easy function for novice programmers to understand
Which is exactly why they shouldn't use it. The problem with goto is that it becomes easy to make spaghetti-code; an unreadable, unmaintainable, unfixable mess. To use goto without doing this on anything other than a piece of toy code requires experience, knowledge, design, testing.... essentially all the qualities novices don't have.
Novices have one good chance to learn how to use loops properly. It is extraordinarily difficult to relearn how to code a few years into the future because everything you learned is bloody awful. Learn it correctly now, at the start.