-4

I am the very beginner of the developing field, and I am facing a problem in Pseudo code random error in C++ language. I think the Error in my program is: { srand(time (NULL)); }

Please help me how can I remove this error and the reason of error. The program I developed is below,

#include<iostream>
using namespace std;
main()
{
       int lowerRange;
       int upperRange;
       lowerRange=1;
       upperRange=1;
       int secretNumber;
       int guess;
       guess=10;

       cout<<"My Student ID is BC130400789 "<<endl;
       cout<<"Enter lower range : ";
       cin>>lowerRange;

       cout<<"Enter upper range : ";
       cin>>upperRange;

       cout<<"Computer is calculating a random secret number in the given range...Done!"<<endl;
       cout<<"\nPlease guesss the secret number in the range ["<<lowerRange<<" - "<<upperRange<<"]: ";
       cin>>guess;

       if(guess<10)
       {
                    cout<<"You won! You guess the correct number.. ";
                    }
        else 
        {
             cout<<"Oooppsss...Your entered number is too high...Computer won"<<endl<<endl;

            }


            { srand(time (NULL));}


             secretNumber = rand()%10+1;
             cout<<"Secret number was: "<<secretNumber<<endl<<endl;
             }
                         system("pause");
       }

2 Answers2

1
  1. main HAS TO return int
  2. rand() is defined in cstdlib which you don't include
  3. You also need to include ctime for time function
  4. As said by G. Samaras you shouldn't use system("pause") (also you don't include required header for it) and you have mismatched {}.

I would also recommend you reading something about code formatting.

Sopel
  • 1,179
  • 1
  • 10
  • 15
0

You have an extra bracket at the end. Remove this and the system("pause"); and you will get no errors. Also main() usually returns an int, thus make it int main().


system(“pause”); - Why is it wrong?

Community
  • 1
  • 1
gsamaras
  • 71,951
  • 46
  • 188
  • 305