If you compile this simple program you will se what I am trying to get it to do. It all works fine other than the fact that if you get it win on you'r last try, it will say that you lost even though when it displays the numbers out, you see that you did not loose, you won. Although the computer doesn't see it that way. I don't know why it is doing this.
Thanks, August
(Script I was talking about is below.)
Code:
#include <iostream>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <fstream>
using namespace std;
int rand_0toN1(int n);
int main(){
double lev_dif, lev_left, lev_play, lev_guess, lev_rand, goto_starter;
srand(time(NULL)); // Set a seed for random-num. generation.
souldnt_go:
for(goto_starter=(99);goto_starter>50;){
clrscr();
cout<<"Choose level difficultey:"<<endl;
cout<<endl;
cout<<"1 - Super Hard"<<endl;
cout<<"2 - Hard"<<endl;
cout<<"3 - Medium"<<endl;
cout<<"4 - Easy"<<endl;
cout<<"5 - Super Easy"<<endl;
cout<<"6 - Exit"<<endl;
cout<<"\nOption: ";
cin>>lev_dif;
if(lev_dif == 6){
clrscr();
return 0; }
else if(lev_dif < 1){
goto_starter = (99); }
else if(lev_dif > 5){
goto_starter = (99); }
else{
goto go_break; }}
go_break:
clrscr();
lev_play=(lev_dif + 2);
lev_rand = rand_0toN1(99) + 1;
cout<<"Guess a number bettween one and a hundred."<<endl;
cout<<"Beginning Level "<<lev_dif;
cout<<"\n"<<endl;
for(lev_left = lev_play;lev_left > 0;lev_left = (lev_left - 1)){
cout<<"Guess "<<lev_left<<" of "<<lev_play<<": ";
cin>>lev_guess;
if(lev_guess > lev_rand){
cout<<"Wrong, guess lower."<<endl; }
else if (lev_guess < lev_rand){
cout<<"Wrong, guess higher."<<endl; }
else if (lev_guess == lev_rand){
cout<<"Right, you won!"<<endl;
cout<<"The number was "<<lev_rand<<endl;
getch( );
goto souldnt_go; }
else{
clrscr();
return 0; }}
cout<<"\nSorry, but you lost!"<<endl;
cout<<"The right number was "<<lev_guess<<endl;
getch( );
goto souldnt_go; }
int rand_0toN1(int n) {
return rand() % n; }