1. #1
    EasyHustlin
    EasyHustlin's Avatar Become A Pro!
    Join Date: 07-15-10
    Posts: 633
    Betpoints: 234

    C++ algorithm problem for you programming people

    Sorry if my code is hard to read. I haven't programmed much since I took c++ last year! I'm trying to write a program that summarizes results for 2x round robin parlays. Input the number of teams, the price for each team, and your unit size, and output each individual bet. The code for this looks like:

    int main()
    {
    int num;
    cout << "Enter the number of teams:\n";
    cin >> num;

    string team[num];
    double price[num];
    int unit;
    double mult[num];
    double bet[50][50];//arbitrarily set to 50x50. Each bet will have a value based on the unit size and the multipliers corresponding to that bet.
    double wins = 0.0;
    double losses = 0.0;
    double total = 0.0;

    cout << "Enter the teams and the price one at a time.\n";

    for (int i=0; i<(num); i++)
    {
    cout << "Team: \n";
    cin >> team[i];
    cout << "Price: \n";
    cin >> price[i];
    **

    cout << "Enter unit size:\n";
    cin >> unit;

    for (int i=0; i<(num); i++)
    {
    mult[i] = 1 + (100/(price[i]));
    **

    for (int j=0; j<(num-1); j++)//creating each combination of 2 team parlay based on corresponding multipliers
    {
    for (int i=(j+1); i
    {
    bet[j][i] = unit * ((mult[j]*mult[i])-1);
    **
    **

    cout << "Summary: \n";

    for (int j=0; j<(num-1); j++)//outputting every combination and how much is to be won for each
    {
    for (int i=(j+1); i
    {
    cout << "\n" << team[j] << "\n" << team[i] << "\n Bet " << unit << " to win " << bet[j][i] << ".\n";
    **
    **

    return 0;
    Easy enough. Now I would like to add an output that summarizes the results if a certain team loses. The algorithm I have written is:

    for (int k=0; k<(num-1); k++)
    {
    for (int j=k; j<(num-1); j++)
    {
    for(int i=0; i
    {
    if ((j=k) or (i=k))
    losses = unit * (num-1);

    if (((j>k) or (jk) or (i
    wins = wins + bet[j][i];

    **
    **

    total = losses - wins;
    cout << "If " << team[k] << " loses, you lose " << total << ".\n";
    total = 0.0;
    wins = 0.0;
    **

    wins = 0.0;
    total = 0.0;

    for (int j=0; j<(num-1); j++)//summarizing results if each team wins
    {
    for (int i=(j+1); i
    {
    wins = wins + bet[j][i];
    **
    **

    cout << "If all teams win, you win " << wins << ".\n";
    But for some reason, the program compiles but stops running when it reaches the first loop. Which is odd because I traced the loop and still don't see how it's not working. Anyone know why, or know of a better algorithm to use? Thanks!

    EDIT: This came out all whack, fixing... The "**" should just be brackets. Don't know why sbr is f*cking up the code so badly.
    Last edited by EasyHustlin; 12-28-10 at 10:05 PM.

  2. #2
    Ganchrow
    Nolite te bastardes carborundorum.
    Ganchrow's Avatar Become A Pro!
    Join Date: 08-28-05
    Posts: 5,011
    Betpoints: 1088

    Hard to tell with code looking so mangled, but after a perfunctory look it appears that when you wrote:
    Code:
    if ((j=k) or (i=k))
    you might have meant:
    Code:
    if ((j==k) or (i==k))
    By the way, on vBulletin you can wrap posted code with [code][/code] tags for improved readability.

  3. #3
    dr_wolf
    dr_wolf's Avatar SBR PRO
    Join Date: 07-20-10
    Posts: 417
    Betpoints: 19055

    tell me what you want to make and i make your code is quite simple.

  4. #4
    donsirlisir
    donsirlisir's Avatar Become A Pro!
    Join Date: 08-02-10
    Posts: 643

    you're still a dummy. the program code would be written in very few lines. so post the problem and i'll write the program

  5. #5
    EasyHustlin
    EasyHustlin's Avatar Become A Pro!
    Join Date: 07-15-10
    Posts: 633
    Betpoints: 234

    Quote Originally Posted by Ganchrow View Post
    Hard to tell with code looking so mangled, but after a perfunctory look it appears that when you wrote:
    Code:
    if ((j=k) or (i=k))
    you might have meant:
    Code:
    if ((j==k) or (i==k))
    By the way, on vBulletin you can wrap posted code with [code][/code] tags for improved readability.
    Thanks much Ganchrow! That fixes it.

  6. #6
    wrongturn
    Update your status
    wrongturn's Avatar Become A Pro!
    Join Date: 06-06-06
    Posts: 2,228
    Betpoints: 3726

    Looks like you missed the first day of that class.

Top