Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
C++ Bowling Assignment Help
Old 03-26-2009, 04:17 PM C++ Bowling Assignment Help
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
OK, I could really use some assistance with this project. I feel very lost and the instructors didn't explain the basic core concepts of the C++ language very well to me (spent a few hours with them the past few weeks). So perhaps someone could guide me through the process step-by-step. I thought I had a fairly good grasp on basic programming concepts, but not since I started taking the class, all that's happened in the course so far just further confused me.

I think I'd be better off just trying to do this myself, but I still haven't found many good C++ tutorials online anywhere, despite the hours of searching I've conducted.

I'm suppose to create a 3 frame bowling game, complete with pin number validation and proper scoring layout.

Here is where the complete assignment is located, to see exactly what I'm suppose to code:
http://www.cs.uwm.edu/classes/cs201/.../06/06/06.html

So far here is the C++ code I came up with:
Code:
#include <iostream>
using namespace std;

void score (int);

int main ()
{
}



int valid (int roll)
{
  int b1, b2, b3, b4, b5, b6, b7;
  b1=b2=b3=b4=b5=b6=b7=-1;

  b1 = valid(10);
  if (!(b1 < 10)){
    cout << "Frame1 - Roll2: ";
    b2 = valid(10 - b1);
  }

  b3 = valid(10);
  if (!(b3 == 10)){
    cout << "Frame2 - Roll2: ";
    b4 = valid(10 - b3);
  }

  b5 = valid(10);
  if(b5 == 10){
    cout << "Frame3 - Roll2: ";
    b6 = valid(10);
  }

  if (!(b5 == 10)){
    b6 = valid(10 - b5);
  }

  if (b5 + b6 >= 10){
    b7 = valid(10);
  }

  return 0;

}
So far I've just been trying to work on one section at a time, beginning with the integer validation, but I'm not even sure if this works.

I'll offer TP to anyone wo can help me out, it'll be greatly appreciated.

(BTW, if anyone knows of any good compilers I could use, that'll also help, the schools compilers are strange too, and I don't know if they'll work on my local machine.)
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
 
Register now for full access!
Old 03-27-2009, 03:36 PM Re: C++ Bowling Assignment Help
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
I take it nobody wants TP then?

OK, maybe I was a little unclear of what I'm looking for. I want to know what the BEST way to go about doing this assignment would be?

Maybe it would be better to just forget that code I posted, I don't understand the "valid" option of C++ very well, it's just what my instructor told me to insert into the program. I just decided it would be easier to break up the program into parts and start with it, but it's not working that well for me.

I do feel I have a basic grasp of some programming concepts here, (if-else for conditionals, cin/cout for requesting and outputting data, return 0 to kill the function, etc. I think when the functions start to appear is when it begins to lose me. What they told me in class made absolutely no sense and when I asked them to explain it, that didn't really help either.)

Is there any other info I should give out here? Sorry if I sound rushed, but I need this assignment completed by Monday (it's due date) and I wanted to work ahead on it.
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 03-27-2009, 08:41 PM Re: C++ Bowling Assignment Help
NullPointer's Avatar
Will Code for Food

Posts: 2,784
Name: Matt
Location: Irvine, CA
Trades: 0
That function valid that you wrote doesn't make a whole lot of sense to me and seems to be an infinite recursion. Also in C++ its a common practice for the main function to return 0, not every function. I glanced at the specs for the project and it seems to me that the function valid is supposed to check if the sum of all of the pins knocked down (as entered by the user) exceeds 10. In which case it would look something like this:
Code:
private bool valid(int rollOne, int rollTwo, int rollThree)
{
     //check if each input is within the required range
     int rolls[3];
     rolls[0] = rollOne;
     rolls[1] = rollTwo;
     rolls[2] = rollThree;
     for(int i = 0; i < 3; i++)
     {
          if(rolls[i] < 0 || rolls[i] > 10)
               return false;
     }

     //check if sum is greater than 10
     if((rollOnce + rollTwo + rollThree) > 10)
          return false;

     return true;
}
Overall I think the program should look a bit like this:
Code:
int main()
{
     int score = 0;
     int rollOne = 0;
     int rollTwo = 0;
     int rollThree = 0;

     for(int i = 0; i < 3; i++)
     {
          int frameTotal = 0;
     
          //prompt user for input
          cout << "Enter pin total:" << endl;
          cin >> rollOne;

          if(valid(rollOne, 0, 0))
          {
               frameTotal += rollOne;
          }
          else
          {
                 //input was invalid
          }
          
          if(frameTotal < 10)
          {
               //promt user for second roll input
               cout << "Enter pin total:" << endl;
               cin >> rollTwo;
 
               //check if input is valid and add score to total


              //
             //if it is the third frame do a third roll
          }

          score += frameTotal;
     }
     
     return 0;
}
Note that I didn't write the complete program, but hopefully a good start. I taught C++ for a summer a couple of years ago but I have been a java programmer almost exclusively since, so my code might be a bit off.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 03-27-2009 at 08:47 PM.. Reason: Fixed bug
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 03-27-2009, 10:21 PM Re: C++ Bowling Assignment Help
Junior Talker

Posts: 1
Trades: 0
idk how to do that one but assignment 5 should look like
Code:
 
#include <iostream>
using namespace std;
void print(int b);
 
int main ()
{
  int b1, b2, b3, b4, b5, b6, b7;
  b2 = -1, b4 = -1, b7 = -1;
 
  cout << "Enter pin total 1st ball frame 1: ";
  cin >> b1;
if (b1 <10)
{
cout << "enter pin total 2nd ball frame 1: "
cin >> b2;
}
else if (b1 >= 0 && b1 < 10)
{
cout << b1;
}
 
cout << "enter pin total 1st ball frame 2: ";
cin >> b3;
if (b3 < 10)
{
cout << "enter pin total 2nd ball frame 2: ";
cin >> b4;
}
 
cout << "enter pin total 1st ball frame 3: ";
cin >> b5;
cout << "enter pin total 2nd ball frame 3: ";
cin >> b6;
if (b5 == 10 || (b5 + b6 == 10 ))
{
cout << "enter pin total for 3rd ball frame 3: "
cin >> b7;
}
 
// frame and ball table skipping frame  ball1  ball2  ball3
cout << "1" << "\t"; print(b1);
cout << "\t" << print(b2);
cout << endl << "2" << "\t"; print(b3);
cout << "\t"; print(b4);
cout << endl << "3" << "\t"; print(b5);
cout << "\t"; print(b6);
cout << "\t"; print(b7);
cout << endl;
}
 
void print(int b)
{
if (b == 10)
{
cout << "X";
}
else if ( b < 0)
{
cout << "-";
}
else
{
cout << b;
}
 
}
idk if that helps but they're based off another oh ps i'm in the class too i have no idea how to do #6 lol
runninman1908 is offline
Reply With Quote
View Public Profile
 
Old 03-27-2009, 11:29 PM Re: C++ Bowling Assignment Help
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
Thanks, Matt. I know most mains have a return 0, I just wasn't finished coding the main function, was just working on the valid part .

Yeah, I think it's the functions that are messing me up. Some parts of the code you wrote I have no idea about, so I'll try to explain the best to my knowledge so I can understand it better.

Once we reach the 'for' function:
  1. Are these basically functions inside functions?
  2. Also, why do we set the 'i' variable to 0 and less than 3?
  3. And I'm not even sure what the i++ means.
  4. Then, where does the 'int frameTotal' and 'int roll' variables '= 0' come from? Shouldn't they be undefined variables, like x, y, z, etc. or something, given that the user will input their values?
Code:
     for(int i = 0; i < 3; i++)
     {
          int frameTotal = 0;
Also, what's the best way to test and compile this code? My uni uses a special unix style command line system and don't know how that's setup on the school's servers. I already tried downloading several "supposed compilers" like putty and Visual C++ 2008 Express, but I can't get them running properly (It's kinda frustrating ).I just need something to make sure it's working OK, nothing to upload or FTP or anything, just the simpler the better...
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 03-27-2009, 11:59 PM Re: C++ Bowling Assignment Help
NullPointer's Avatar
Will Code for Food

Posts: 2,784
Name: Matt
Location: Irvine, CA
Trades: 0
Regarding the compiler. I have visual studio, and I've never used any other (other than visual c++ express, which is the same compiler), but that should work just fine for your purposes.

The syntax I was using is called a for loop, its not a function. Basically it means that while the integer i is less than 3 execute the code inside the loop body. i++ means to increase i by one at each interval.

Regarding the variables I declared, before a value can be assigned to them by cin they must be declared. The frame total variable keeps track of the total points for that frame, so it must be initialized to zero. The other variables, I suppose could go without being initialized.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 03-28-2009, 12:14 AM Re: C++ Bowling Assignment Help
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
@runninman = I know they told us to "Build some of it" off assignment 5, but they didn't explain that very well either...

@Matt = I guess I thought it was a function because we haven't reached loops yet, I think that's for towards the end of the semester.

Do you just use the Command Prompt VS provides? I've looked into Studio's "Help" Menus (Or lack thereof), and didn't say anything about strictly converting code to visual output. Much of the How-To's provided there are too advanced for a coder of my level. I sepnt hours searching through it for things like "commands allowed" or "C++ code compiling" and came away with nothing but a headache.

Even just a link to a basic page with that info would be useful.
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 03-28-2009, 12:36 AM Re: C++ Bowling Assignment Help
NullPointer's Avatar
Will Code for Food

Posts: 2,784
Name: Matt
Location: Irvine, CA
Trades: 0
I'm not 100% sure what you mean when you say visual output, if your program has any output it should be visible in the console. If your problem is not being able to see your output before the program closes (ie main returns) add the function call getchar() right before return 0 in main.

If you're having trouble running and compiling your code in VS I'll walk you through the process:

For simple projects in VS, you'll want to make sure that when you create a new project that you select win32 console application and then set it as an empty project (just follow the menus and you'll see the options).

From here you can create your project files by right clicking Source Files and selecting New Item..

After you've written your code, to compile it select build from the top menu and then build solution. This will create an executable in your project directory. To run it from VS select the Debug menu and then Start Debugging.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 03-28-2009, 12:54 AM Re: C++ Bowling Assignment Help
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
Awesome, thanks. I don't know why they don't just say that in the help menus or forums or something. That could make a great blog post .

What I meant by "visual output" meaning just the screen where the user interacts with the code, enters numbers, etc. Maybe I just got the technical term wrong.

The only issue now is that the (second block of) code from post 3 is giving me a "'valid': identifier not found" error. I'll just have to work on it from there.
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 03-28-2009, 01:05 AM Re: C++ Bowling Assignment Help
NullPointer's Avatar
Will Code for Food

Posts: 2,784
Name: Matt
Location: Irvine, CA
Trades: 0
In C++ functions have to be declared BEFORE they can be called, unlike in java or PHP where the compiler will actually go find function definitions.
Code:
bool valid();

int main()
{
     //main code
}

bool valid()
{
     //valid code
}
I think that will solve the problem you are having.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 03-28-2009, 01:24 AM Re: C++ Bowling Assignment Help
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
Different error now, it's saying I have a '"valid' : function does not take 3 arguments" error (on line 21), if(valid(rollOne, 0, 0)).

Does this mean that we have to change the bool valid(); declaration (on line 4) by giving it a parameter value?
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 03-28-2009, 02:25 AM Re: C++ Bowling Assignment Help
NullPointer's Avatar
Will Code for Food

Posts: 2,784
Name: Matt
Location: Irvine, CA
Trades: 0
Sorry the code I gave was just an example, when you declare the function you must also declare its inputs:
Code:
bool valid(int rollOne, int rollTwo, int rollThree);

int main()
{

}

bool valid(int rollOne, int rollTwo, int rollThree)
{

}
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 03-28-2009, 01:26 PM Re: C++ Bowling Assignment Help
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
OK no more errors, now I just need to work on the latter half of the assignment (displaying the scores).

Thanks again for all the help.
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Reply     « Reply to C++ Bowling Assignment Help
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.47384 seconds with 12 queries