Be a Supporter!

c++ help please

  • 159 Views
  • 5 Replies
New Topic Respond to this Topic
Peaceblossom
Peaceblossom
  • Member since: Dec. 23, 2003
  • Offline.
Forum Stats
Member
Level 25
Reader
c++ help please 2005-01-27 22:19:40 Reply

in this code it says that there are 2 else statements without matching if statements. can somebody tell me where this is true? please help with this.

#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;

int main()
{
srand( (unsigned)time( NULL ) );
int rps;
int random = (rand()%21);
cout<<"Rock, Paper, Scissors"<<endl;
cout<<"---------------------"<<endl;
cout<<"--By Steven Fowler.--"<<endl;
cout<<"--Press 1 For Rock,--"<<endl;
cout<<"--Press 2 For Paper--"<<endl;
cout<<"-And 3 For Scissors.-"<<endl;
cin>>rps;
if(random <= 6){
if(rps == 1){
cout<<"Computer Chooses Rock"<<endl;
cout<<"The Game Is Tied, Exit And Re-Run to Play Again"<<endl;
cin.ignore();
cin.ignore();
return 0;
}else{
if(rps == 2){
cout<<"Computer Chooses Rock"<<endl;
cout<<"You Win! Exit And Re-Run To Play Again"<<endl;
cin.ignore();
cin.ignore();
return 0;
}else{
if(rps == 3){
cout<<"Computer Chooses Rock"<<endl;
cout<<"You Lose! Exit And Re-Run To Play Again"<<endl;
cin.ignore();
cin.ignore();
return 0;
}
}
}else{
if(random <= 13){
if(rps == 1){
cout<<"Computer Chooses Paper"<<endl;
cout<<"You Lose! Exit And Re-Run to Play Again"<<endl;
cin.ignore();
cin.ignore();
return 0;
}else{
if(rps == 2){
cout<<"Computer Chooses Rock"<<endl;
cout<<"The Game Tied! Exit And Re-Run To Play Again"<<endl;
cin.ignore();
cin.ignore();
return 0;
}else{
if(rps == 3){
cout<<"Computer Chooses Rock"<<endl;
cout<<"You Win! Exit And Re-Run To Play Again"<<endl;
cin.ignore();
cin.ignore();
return 0;
}
}else{
if(random <= 20){
if(rps == 1){
cout<<"Computer Chooses Scissors"<<endl;
cout<<"You Win! Exit And Re-Run to Play Again"<<endl;
cin.ignore();
cin.ignore();
return 0;
}else{
if(rps == 2){
cout<<"Computer Chooses Rock"<<endl;
cout<<"You Lose! Exit And Re-Run To Play Again"<<endl;
cin.ignore();
cin.ignore();
return 0;
}else{
if(rps == 3){
cout<<"Computer Chooses Rock"<<endl;
cout<<"You Have Tied! Exit And Re-Run To Play Again"<<endl;
cin.ignore();
cin.ignore();
return 0;
}else{
return 0;
}
}
}
}
}
}
}
}
}
}


BBS Signature
W35
W35
  • Member since: Oct. 14, 2003
  • Offline.
Forum Stats
Member
Level 40
Blank Slate
Response to c++ help please 2005-01-27 22:52:57 Reply

You really should use comments to help with this.
Example:
} //END IF

Youve made that whole code so hard to read/understand I coudld be wrong, but I think that second last } doesnt do anything. I couldnt find the specific problem though.


BBS Signature
Peaceblossom
Peaceblossom
  • Member since: Dec. 23, 2003
  • Offline.
Forum Stats
Member
Level 25
Reader
Response to c++ help please 2005-01-27 22:55:34 Reply

thats alright i found out what was wrong.


BBS Signature
pieoncar
pieoncar
  • Member since: Apr. 21, 2004
  • Offline.
Forum Stats
Member
Level 53
Blank Slate
Response to c++ help please 2005-01-27 22:55:39 Reply

At 1/27/05 10:19 PM, eh-productions wrote: in this code it says that there are 2 else statements without matching if statements.

Hahaha, that's what you get for putting the whole program in main(). I hope you learn a lesson from this.

Ravens-Grin
Ravens-Grin
  • Member since: Jun. 3, 2003
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to c++ help please 2005-01-27 23:02:40 Reply

I was about to say the same thing. Learn how to use some functions and how to pass values between functions. Extremely easy and very very helpful.

Peaceblossom
Peaceblossom
  • Member since: Dec. 23, 2003
  • Offline.
Forum Stats
Member
Level 25
Reader
Response to c++ help please 2005-01-27 23:05:30 Reply

this works for me. i don't care if others can read it very well its not my problem. plus i have only had c++ for one month and only read about it about 2 hours every weekend.


BBS Signature