Results 1 to 4 of 4

Thread: Qtcreator won't calculate correctly

  1. #1
    Join Date
    Apr 2011
    Posts
    67
    Thanks
    22
    Thanked 5 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Qtcreator won't calculate correctly

    I have the following console program on qtcreator 4.7.

    Qt Code:
    1. #include <iostream>
    2. #include <cstdlib>
    3. using namespace std;
    4.  
    5. int main()
    6. {
    7. int a;
    8. int b;
    9. int result = a * b;
    10.  
    11. cout<<"Enter a";
    12. cin>>a;
    13.  
    14. cout<<"Enter b";
    15. cin>>b;
    16.  
    17. cout<<"You entered"<<a<<"and you entered"<<b<<"Their product is"<<result<<endl;
    18. cout << "Press any key to exit..." << endl;
    19. system ("pause");
    20. return 0;
    21. }
    To copy to clipboard, switch view to plain text mode 

    When i input 5 and 9,i get You entered5and you entered9Their product is-2009147472

    why am i not getting 45?.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Qtcreator won't calculate correctly

    Hm, that's just a guess, but maybe you should calculate the result after the user has entered the numbers...

  3. #3
    Join Date
    Apr 2011
    Posts
    67
    Thanks
    22
    Thanked 5 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qtcreator won't calculate correctly

    Thanks,that was the problem.

    Qt Code:
    1. cout<<"Enter a";
    2. cin>>a;
    3.  
    4. cout<<"Enter b";
    5. cin>>b;
    6.  
    7. int result = a * b;
    To copy to clipboard, switch view to plain text mode 

    worked.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qtcreator won't calculate correctly

    This question has precisely nothing to do with either Qt or Qt creator.

    For future reference, the language you are writing code in is called C++.

Similar Threads

  1. Calculate scene coordinates from QGraphicsLinearLayout
    By onurozcelik in forum Qt Programming
    Replies: 2
    Last Post: 21st January 2011, 08:38
  2. calculate draw time
    By johnsoga in forum Qt Programming
    Replies: 1
    Last Post: 30th May 2009, 02:03
  3. use Latitude and longitude to calculate distance?
    By lengshuang in forum General Programming
    Replies: 6
    Last Post: 11th May 2009, 14:06
  4. how to calculate difference b/w two times
    By dummystories in forum Newbie
    Replies: 1
    Last Post: 9th March 2009, 13:58
  5. How to calculate Monitor Resolution?
    By ashukla in forum Qt Programming
    Replies: 2
    Last Post: 7th October 2007, 07:28

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.