Results 1 to 2 of 2

Thread: Need fast HELP on work to SCHOOL!!

  1. #1

    Default Need fast HELP on work to SCHOOL!!

    Hello!
    So im noob at this c++ stuff and i need to program output like this:

    Write number:
    -2 // im writing number in Runing program
    Write number:
    1
    Write number:
    -1
    Write number:
    12
    Write number:
    0
    SUM of positive numbers: 13
    SUM of negative numbers: -3

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Need fast HELP on work to SCHOOL!!

    Your post has nothing to do with Qt and should be posted in the General Programming forum. That said, let me know what type of grade we get:
    Qt Code:
    1. int main () {
    2.  
    3. int numbers[] = {-2, 1, -1, 12, 0};
    4.  
    5. int sum_positive = 0;
    6. int sum_negative = 0;
    7.  
    8. int size = sizeof(numbers)/sizeof(int);
    9.  
    10. for (int i = 0; i < size; i++)
    11. {
    12. std::cout << "Write number:" << std::endl;
    13. std::cout << numbers[i] << std::endl;
    14. if (numbers[i] > 0)
    15. sum_positive += numbers[i];
    16. else if (numbers[i] < 0)
    17. sum_negative += numbers[i];
    18. }
    19.  
    20. std::cout << "SUM of positive numbers: " << sum_positive << std::endl;
    21. std::cout << "SUM of negative numbers: " << sum_negative << std::endl;
    22.  
    23. return 0;
    24. }
    To copy to clipboard, switch view to plain text mode 
    Shows the following output:
    Qt Code:
    1. Write number:
    2. -2
    3. Write number:
    4. 1
    5. Write number:
    6. -1
    7. Write number:
    8. 12
    9. Write number:
    10. 0
    11. SUM of positive numbers: 13
    12. SUM of negative numbers: -3
    To copy to clipboard, switch view to plain text mode 
    I was bored so I posted the code, next time show what you have tried and what you are having issues with. You'll find people are willing to help when you show your work.


    Added after 6 minutes:


    I must be really bored, optimized version below:
    Qt Code:
    1. int main () {
    2.  
    3. int numbers[] = {-2, 1, -1, 12, 0};
    4.  
    5. int sum_positive = 0;
    6. int sum_negative = 0;
    7.  
    8. int size = sizeof(numbers)/sizeof(int);
    9.  
    10. for (int i = 0; i < size; i++)
    11. {
    12. int number = numbers[i];
    13. std::cout << "Write number:" << std::endl;
    14. std::cout << number << std::endl;
    15. if (number > 0)
    16. sum_positive += number;
    17. else
    18. sum_negative += number;
    19. }
    20.  
    21. std::cout << "SUM of positive numbers: " << sum_positive << std::endl;
    22. std::cout << "SUM of negative numbers: " << sum_negative << std::endl;
    23.  
    24. return 0;
    25. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jefftee; 8th November 2016 at 02:16.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

Similar Threads

  1. Problem with school project, Raspberry & Bigbelly
    By kohiiro in forum Qt Programming
    Replies: 0
    Last Post: 14th March 2016, 08:40
  2. School project using Qt
    By Latvian in forum Newbie
    Replies: 1
    Last Post: 7th May 2012, 01:56
  3. fast drawing in Qt
    By franco.amato in forum Qt Programming
    Replies: 0
    Last Post: 23rd November 2009, 22:22
  4. Qt3 more fast than Qt4 ?
    By commarmi in forum Qt Programming
    Replies: 11
    Last Post: 14th September 2007, 15:36
  5. 'Big' QT Project for school
    By Sicko in forum Qt Programming
    Replies: 17
    Last Post: 18th December 2006, 06:25

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.