Windows gives an error after starting the .exe

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Apr 2004
Posts: 128
Reputation: johnroach1985 is an unknown quantity at this point 
Solved Threads: 0
johnroach1985's Avatar
johnroach1985 johnroach1985 is offline Offline
Junior Poster

Windows gives an error after starting the .exe

 
0
  #1
Jun 17th, 2005
Hi i am re-studying C.So I just wanted to do a simple calculator program.I am using dev-c++ anyways the code is below please help.

  1.  
  2. #include <stdio.h>
  3. #include <conio.h>
  4.  
  5.  
  6. /*its a simple program that after getting the numbers from the user and inputs the
  7. operation*/
  8.  
  9.  
  10.  
  11. int main()
  12.  
  13. {
  14.  
  15. int i=0;
  16. int a=0;
  17. int b=0;
  18. int s=0;
  19. char o;
  20.  
  21. while(i==i){ /*a simple for-ever loop*/
  22. printf("Enter the first number");
  23. scanf("%d",&a);
  24.  
  25. printf("Enter the second number");
  26. scanf("%d",&b);
  27.  
  28. printf("What do you want to do with them?");
  29. scanf("%c",o);
  30.  
  31. switch(o)
  32. {
  33. case '+': s=a+b;
  34. printf("\n The sum is : %d" ,s);
  35. scanf("");
  36. break;
  37.  
  38. default :
  39. printf("\n invalid");
  40. scanf("");
  41. break;
  42. }
  43.  
  44.  
  45. }
  46. }
"By the data to date, there is only one animal in the Galaxy dangerous to man—man himself. So he must supply his own indispensable competition. He has no enemy to help him."
From Time Enough for Love by Robert A. Heinlein
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,359
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 239
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Windows gives an error after starting the .exe

 
0
  #2
Jun 17th, 2005
Originally Posted by johnroach1985
Hi i am re-studying C.So I just wanted to do a simple calculator program.I am using dev-c++ anyways the code is below please help.
It's easier to provide answers when you provide questions.

You may want to take a look at a way to Read a Line of Text from the User and a way to Read a Number from the User.

scanf has a lot of issues that trip up beginners.
  1. scanf("%d",&b);
  2.  
  3. printf("What do you want to do with them?");
  4. scanf("%c",o);
Like the newline being left in the buffer. Or that a pointer must be passed.
scanf("%c",&o);
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 128
Reputation: johnroach1985 is an unknown quantity at this point 
Solved Threads: 0
johnroach1985's Avatar
johnroach1985 johnroach1985 is offline Offline
Junior Poster

Re: Windows gives an error after starting the .exe

 
0
  #3
Jun 18th, 2005
sorry man youre right i can't believe it i forgot to write an answer ok i'll look into the links now.And by the by the question was that windows kept giving me an error whe i run the program.But le me try the things you've said.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 128
Reputation: johnroach1985 is an unknown quantity at this point 
Solved Threads: 0
johnroach1985's Avatar
johnroach1985 johnroach1985 is offline Offline
Junior Poster

Re: Windows gives an error after starting the .exe

 
0
  #4
Jun 18th, 2005
And It Works Thanks Man....
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC