| | |
stuck please help-quick question
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
hello, I am following a book and im stuck on this one.....(note it's tacky but just bear with me, im a newb)
I know im using the old .h header files, because that's what the book uses (it says i can use the new standards if i want, using namespace std but my code tends to not work sometimes. So im sticking to the old ones just untill i get the hang of things.
Anyway i compiled the following on devc++ and it runs the first few line well untill the command promt suddently closes after line 9.
The code seems to be fine because it compiled, but it just flashes.
Any ideas as to what im doing wrong?....
-Thanks
C++ Syntax (Toggle Plain Text)
#include <iostream.h> int main() { int RedSoxScore, YankeesScore; cout<<"Enter the score for the RedSox:"; cin>> RedSoxScore; cout<<"Enter the score for the yankees:"; cin>> YankeesScore; cout<<"\n"; if (RedSoxScore > YankeesScore) cout<<"GO THE BLIMMIN REDSOX!!\n"; if (YankeesScore > RedSoxScore ) { cout<<"WHOOPY GO THE YANKS!!!\n"; cout<<"Happy days in NYC!!!\n"; } if (RedSoxScore == YankeesScore) { cout<<"A tie?, nha cant be!\n"; cout<<" Give me the real score for the yanks:"; cin >> YankeesScore; if (RedSoxScore > YankeesScore) cout<<"Knew it, Go the sox!!"; if (YankeesScore > RedSoxScore) cout<<"Knew it go the yanks!!"; if (YankeesScore == RedSoxScore) cout<<"Wow, it was tie!?"; } cout<<"\nThanks for telling me.\n"; return 0; }
I know im using the old .h header files, because that's what the book uses (it says i can use the new standards if i want, using namespace std but my code tends to not work sometimes. So im sticking to the old ones just untill i get the hang of things.
Anyway i compiled the following on devc++ and it runs the first few line well untill the command promt suddently closes after line 9.
The code seems to be fine because it compiled, but it just flashes.
Any ideas as to what im doing wrong?....
-Thanks
Last edited by Ancient Dragon; Dec 18th, 2007 at 10:01 am. Reason: corected code tags
•
•
Join Date: Sep 2006
Posts: 327
Reputation:
Solved Threads: 22
Take a look here at cin.ignore() and cin.get()
http://www.cprogramming.com/tutorial/lesson1.html
http://www.cprogramming.com/tutorial/lesson1.html
Hi revenge2,
I looked in your code. It works as expected. I don't understand what do you mean by "flashing". You may like to add followin lines before return.
I am using Microsoft C++ therefore I used you may use anything which blocks the execution and let your program eait for user input.
Final code looks like...
I looked in your code. It works as expected. I don't understand what do you mean by "flashing". You may like to add followin lines before return.
I am using Microsoft C++ therefore I used
C++ Syntax (Toggle Plain Text)
_getch
Final code looks like...
C++ Syntax (Toggle Plain Text)
cout<<"Press any key to continue." int i = _getch();
c++ Syntax (Toggle Plain Text)
#include "conio.h" #include<iostream> using namespace std ; int _tmain(int argc, _TCHAR* argv[]) { int RedSoxScore, YankeesScore; cout<<"Enter the score for the RedSox:"; cin>> RedSoxScore; cout<<"Enter the score for the yankees:"; cin>> YankeesScore; cout<<"\n"; if (RedSoxScore > YankeesScore) cout<<"GO THE BLIMMIN REDSOX!!\n"; if (YankeesScore > RedSoxScore ) { cout<<"WHOOPY GO THE YANKS!!!\n"; cout<<"Happy days in NYC!!!\n"; } if (RedSoxScore == YankeesScore) { cout<<"A tie?, nha cant be!\n"; cout<<" Give me the real score for the yanks:"; cin >> YankeesScore; if (RedSoxScore > YankeesScore) cout<<"Knew it, Go the sox!!"; if (YankeesScore > RedSoxScore) cout<<"Knew it go the yanks!!"; if (YankeesScore == RedSoxScore) cout<<"Wow, it was tie!?"; } cout<<"\nThanks for telling me.\n"; cout<<"Press any key to continue." int i = _getch(); return 0; }
Last edited by Ancient Dragon; Dec 18th, 2007 at 10:38 am. Reason: add line numbers
I know I am. Therefore I am.
>>_getch_getch
This is a C++ program, not C. So don't use that C function. Use cin.ignore() or cin.get() so that you don't mix C and C++ in the same program. Sure of course getch() works, but its not consistent and you might get lower marks from your instructor for using it.
This is a C++ program, not C. So don't use that C function. Use cin.ignore() or cin.get() so that you don't mix C and C++ in the same program. Sure of course getch() works, but its not consistent and you might get lower marks from your instructor for using it.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
unfortunately i dont undertand that, ahh i have only been using iostream for the purpose of learning plus the book seems to use this for the time being. I dont have an instructor/teacher or anything im just trying to learn from home, after school.
Anyway is there anywway to dum it down a bit?! like explain what "cin.ignore()" does exactly-oh and please dont mix c with c++ i get even more lost (lol)
Flashing meaning; when i run the program and enter the score' at line 9 the command prompt just closes before i see or get to do anything.
-thanks
Anyway is there anywway to dum it down a bit?! like explain what "cin.ignore()" does exactly-oh and please dont mix c with c++ i get even more lost (lol)
Flashing meaning; when i run the program and enter the score' at line 9 the command prompt just closes before i see or get to do anything.
-thanks
Last edited by revenge2; Dec 18th, 2007 at 10:33 am.
>>I dont have an instructor/teacher or anything im just trying to learn from home, after school.
Good luck. Please don't hesitate to ask questions here.
>>like explain what "cin.ignore()
See this link for some good info about cin
>>does exactly-oh and please dont mix c with c++ i
It means do not mix the two languages in the same program. C++ supports most C functions but it is not considered good programming practice to mix them up. Specifically -- don't use anything found in stdio.h in a c++ program. And don't use anything in conio.h at all because those functions are not standard, which means they may or may not be supported by a compiler.
Good luck. Please don't hesitate to ask questions here.
>>like explain what "cin.ignore()
See this link for some good info about cin
>>does exactly-oh and please dont mix c with c++ i
It means do not mix the two languages in the same program. C++ supports most C functions but it is not considered good programming practice to mix them up. Specifically -- don't use anything found in stdio.h in a c++ program. And don't use anything in conio.h at all because those functions are not standard, which means they may or may not be supported by a compiler.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- Homework help (Java)
- Smart chained select boxes (JavaScript / DHTML / AJAX)
- more syntax questions (Java)
- Compiler Construction (Computer Science)
- Dual Channel ECC/R question (Motherboards, CPUs and RAM)
- Need Help installing Harddrive (Storage)
- AGP support video card question (Monitors, Displays and Video Cards)
- Advanced mySQL Querys (PHP)
- Possible Data Lost, Help! (Windows 95 / 98 / Me)
Other Threads in the C++ Forum
- Previous Thread: Using arrays and menus...
- Next Thread: Need help with (returning) substrings
| Thread Tools | Search this Thread |
api array arrays based binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game generator givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






