This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2009-01-09 22:09:36

terminator355
Scratcher
Registered: 2008-07-31
Posts: 100+

C++ Help

can someone with c++ experience catch any bugs in this and why it doesnt work THX :

Code:

//
//  main.cpp
//  Variables
//
//  Created by Gray Olson on 11/25/08.
//  Copyright __MyCompanyName__ 2008. All rights reserved.
//

// operating with variables

#include <iostream>
#include "conio.h"
#include <stdio.h>
#include <stdlib.h>
#include <Timer.h>
using namespace std;
int main ()
{
    //Variables------------------------------------------------
    int Ur_Sc;
    int Comp_Sc;
    int num;
    int comp_num;
    string mystrg;
    
    //Seting the variables-------------------------------------
    Ur_Sc = 0;
    Comp_Sc = 0;
    
    //Scores---------------------------------------------------
    cout << "Your Score is: " << Ur_Sc;
    cout << " Computer Score is: " << Comp_Sc;
    
    //Controls-------------------------------------------------
    cout << " Type 'yes' to ROLL or 'quit' to QUIT";
    
    //Display Dice--------------------------------------------
    getline (cin, mystrg);
    if (mystrg == "yes") {
        num = 1 + rand () % 6 + 1;
        comp_num = 1 + rand() % 6 + 1;
        
        if (num = 1) {
            cout << " -----" << endl;
            cout << "|     |" << endl;
            cout << "|  O  |" << endl;
            cout << "|     |" << endl;
            cout << " -----" << endl;
        }
        if (num = 2) {
            cout << " -----" << endl;
            cout << "|    O|" << endl;
            cout << "|     |" << endl;
            cout << "|O    |" << endl;
            cout << " -----" << endl;    
        }
        if (num = 3) {
            cout << " -----" << endl;
            cout << "|    O|" << endl;
            cout << "|  O  |" << endl;
            cout << "|O    |" << endl;
            cout << " -----" << endl;    
        }
        if (num = 4) {
            cout << " -----" << endl;
            cout << "|O   O|" << endl;
            cout << "|     |" << endl;
            cout << "|O   O|" << endl;
            cout << " -----" << endl;    
        }
        if (num = 5) {
            cout << " -----" << endl;
            cout << "|O   O|" << endl;
            cout << "|  O  |" << endl;
            cout << "|O   O|" << endl;
            cout << " -----" << endl;    
        }
        if (num = 6) {
            cout << " -----" << endl;
            cout << "|O   O|" << endl;
            cout << "|O   O|" << endl;
            cout << "|O   O|" << endl;
            cout << " -----" << endl;    
        }
        if (comp_num = 1) {
            cout << " -----" << endl;
            cout << "|     |" << endl;
            cout << "|  O  |" << endl;
            cout << "|     |" << endl;
            cout << " -----" << endl;
        }
        if (comp_num = 2) {
            cout << " -----" << endl;
            cout << "|    O|" << endl;
            cout << "|     |" << endl;
            cout << "|O    |" << endl;
            cout << " -----" << endl;    
        }
        if (comp_num = 3) {
            cout << " -----" << endl;
            cout << "|    O|" << endl;
            cout << "|  O  |" << endl;
            cout << "|O    |" << endl;
            cout << " -----" << endl;    
        }
        if (comp_num = 4) {
            cout << " -----" << endl;
            cout << "|O   O|" << endl;
            cout << "|     |" << endl;
            cout << "|O   O|" << endl;
            cout << " -----" << endl;    
        }
        if (comp_num = 5) {
            cout << " -----" << endl;
            cout << "|O   O|" << endl;
            cout << "|  O  |" << endl;
            cout << "|O   O|" << endl;
            cout << " -----" << endl;    
        }
        if (comp_num = 6) {
            cout << " -----" << endl;
            cout << "|O   O|" << endl;
            cout << "|O   O|" << endl;
            cout << "|O   O|" << endl;
            cout << " -----" << endl;    
        }
        if (comp_num > num) {
            cout << "You Lose!";
            return 0;
        }
        if (num > comp_num) {
            cout << "YOU WIN!";
            return 0;
        }
    } else {
        return 0;
    }
}

No new stuff for now guys  wink  join me for some Black Ops on xbox: termhn or for some rock band on PS3: rocket232

Offline

 

#2 2009-01-09 22:11:21

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: C++ Help

Use = to set a value, use == to check for equality

//example
if (num==1){
//code
}

I don't know c or c++, it was just an obvious mistake.

Last edited by archmage (2009-01-09 22:12:29)


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#3 2009-01-09 23:02:25

terminator355
Scratcher
Registered: 2008-07-31
Posts: 100+

Re: C++ Help

thx


No new stuff for now guys  wink  join me for some Black Ops on xbox: termhn or for some rock band on PS3: rocket232

Offline

 

#4 2009-01-20 18:44:01

mgmir
Scratcher
Registered: 2008-09-01
Posts: 9

Re: C++ Help

Not really a comment on your errors (I think someone mentioned the "==" vs "=" comment already) but you may want to use a switch...case statement for the numerous if() statements, just for efficiency.   smile

terminator355 wrote:

can someone with c++ experience catch any bugs in this and why it doesnt work THX

Offline

 

#5 2009-01-20 21:00:45

EveningSage
Scratcher
Registered: 2009-01-10
Posts: 65

Re: C++ Help

I am not very advanced in C++ so i do not know much but i think there are no such thing as case statements in c++ bummer though because in Java those make life so much easier.

Offline

 

#6 2009-01-20 21:14:23

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: C++ Help

Both C++ and java have switch statements.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

Board footer