can someone with c++ experience catch any bugs in this and why it doesnt work THX :
//
// 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;
}
}
join me for some Black Ops on xbox: termhn or for some rock band on PS3: rocket232Offline
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)
Offline
thx
join me for some Black Ops on xbox: termhn or for some rock band on PS3: rocket232Offline
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.
terminator355 wrote:
can someone with c++ experience catch any bugs in this and why it doesnt work THX
Offline
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
Both C++ and java have switch statements.
Offline