C++ algorithm problem for you programming people

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • EasyHustlin
    SBR Wise Guy
    • 07-15-10
    • 633

    #1
    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, 11:05 PM.
  • Ganchrow
    SBR Hall of Famer
    • 08-28-05
    • 5011

    #2
    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.
    Comment
    • dr_wolf
      SBR Sharp
      • 07-20-10
      • 417

      #3
      tell me what you want to make and i make your code is quite simple.
      Comment
      • donsirlisir
        SBR Wise Guy
        • 08-02-10
        • 643

        #4
        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
        Comment
        • EasyHustlin
          SBR Wise Guy
          • 07-15-10
          • 633

          #5
          Originally posted by Ganchrow
          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.
          Comment
          • wrongturn
            SBR MVP
            • 06-06-06
            • 2228

            #6
            Looks like you missed the first day of that class.
            Comment
            SBR Contests
            Collapse
            Top-Rated US Sportsbooks
            Collapse
            Working...