LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-20-2012, 04:22 PM   #16
carlosk711
Member
 
Registered: Sep 2012
Posts: 52

Original Poster
Rep: Reputation: Disabled

Ok thank you, and thanks for the help so far
 
Old 10-20-2012, 04:33 PM   #17
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
Right, I've done roughly half (the first 50 lines):

Code:
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
void remove (int, int, int);
void generate (int, int, int, int );
void print (int, int, int);
int main () {
    int turn=0;
    int heap, deduct, row1, row2, row3, total;
    srand (time(NULL));
    row1 = 0;
    row2 = 0;
    row3 = 0;
    total = 0;
    generate (row1, row2, row3, total);
    print (row1, row2, row3);
    while (total > 0) {
        while (((turn % 10) + 1) == (1 || 3 || 5 || 7 || 9)){
            cout << "Make your move:" << endl;
            cin >> heap >> deduct;
            if (heap == 1){ 
                if (row1 >= deduct){
                    remove (deduct, row1, total);
                    print (row1, row2, row3);
                    turn++;
                } else {
                    cout << "Heap 1 only contains " << row1 << " stones, try again!" << endl;
                }   
            } else if (heap == 2){ 
                if (row2 >= deduct){
                    remove (deduct, row2, total);
                    print (row1, row2, row3);
                    turn++;
                } else {
                    cout << "Heap 2 only contains " << row2 << "stones, try again!" << endl;
                }   
            } else if (heap == 3) {
                if (row3 >= deduct) {
                    remove (deduct, row3, total);
                    print (row1, row2, row3);
                    turn++;
                } else {
                    cout << "Heap 3 only contains " << row3 << "stones, try again!" << endl;
                }   
            } else if (heap > 3) {
                cout << "This heap does not exist, try again." << endl;
            }   
        }   
//...
See how I've structured the if/else blocks: each 'if' line ends in '{', and the following code is indented by one tab, until we reach the '}' which ends the block. This makes it easy to read but won't trigger syntax errors if you don't do it. You do need to have the '{' and '}', or the compiler can't work out which 'else' matches which 'if' - which is what the compiler was complaining about in your code.

Can you do second while loop in a similar style? Also, you might want to consider having an array to store your 'row' values instead of three separate variables: that way instead of having to deal with 'heap == 1', 'heap == 2', 'heap == 3' separately, you can deal with them all the same way.

Hope this helps,

Last edited by Snark1994; 10-20-2012 at 04:35 PM.
 
Old 10-20-2012, 04:40 PM   #18
carlosk711
Member
 
Registered: Sep 2012
Posts: 52

Original Poster
Rep: Reputation: Disabled
I'll try it out and see where I get
 
  


Reply


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
syntax errors connect2janu Programming 1 04-09-2012 08:11 PM
Making a Game, anyone want to help? Newtonx Linux - Games 15 01-19-2007 05:49 AM
"NIM thread blocked" & "Deadman Switch (DMS) close to trigger" errors sosborne Linux - Networking 1 06-28-2006 03:07 PM
"NIM thread blocked" & "Deadman Switch" errors sosborne AIX 3 06-01-2006 12:21 PM


All times are GMT -5. The time now is 03:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration