Thread: hi im new to c++ and my loop wont work :(

  1. #16
    Cat Lover
    Join Date
    May 2005
    Sydney, Australia
    I think I understand what you're asking, though it's rather hard to say.

    Ok, so there's two parts.

    1. You create set C from A and B
    2. You check C against the sum of set B

    Arrays are extremely useful here, and they're quite simple.

    for(int n=0;n<5;n++)
      cout << numbers[n] << endl;
    That goes through numbers and couts the first, second, third, etc. If you don't understand that I would recommend taking a look at a tutorial on arrays, and basic C(++) language.

    So, you go through c[0]+a[0]+b[0] to the end.

    Now for the second part, you can go through your array of numbers in B adding them up.
    for(int n=0;n<10;n++)
      number += n;
    The above adds up all the numbers between 0 and 9, I'm sure you can think of a way to modify that to use an array from before to find the sum of all the numbers in set B.

    Then it's a case of go through each element in set C and check if sum_b <= c[n].

  2. #17
    Registered User
    Join Date
    Dec 2005
    thats exactly what i need thank you very much but the trouble is ill still need to loop the last bit to keep updating (c) ill have a try and see if i can use arrays.
    befor i just used loops but i cant rember which type i used and my program way very long

Popular pages Recent additions subscribe to a feed