944,047 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1425
  • C++ RSS
Jun 17th, 2005
0

Windows gives an error after starting the .exe

Expand Post »
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.

C++ Syntax (Toggle Plain Text)
  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. }
Similar Threads
Reputation Points: 11
Solved Threads: 0
Junior Poster
johnroach1985 is offline Offline
135 posts
since Apr 2004
Jun 17th, 2005
0

Re: Windows gives an error after starting the .exe

Quote 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.
C++ Syntax (Toggle Plain Text)
  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);
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Jun 18th, 2005
0

Re: Windows gives an error after starting the .exe

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.
Reputation Points: 11
Solved Threads: 0
Junior Poster
johnroach1985 is offline Offline
135 posts
since Apr 2004
Jun 18th, 2005
0

Re: Windows gives an error after starting the .exe

And It Works Thanks Man....
Reputation Points: 11
Solved Threads: 0
Junior Poster
johnroach1985 is offline Offline
135 posts
since Apr 2004

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Guess! Guess! n Guess!!!
Next Thread in C++ Forum Timeline: cout << "Please Help" << endl;





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC