6 Replies - 17042 Views - Last Post: 29 January 2009 - 09:06 PM Rate Topic: -----

#1 fhsfootball53   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 27-January 09

Error: expected primary-expression before ')' token

Posted 29 January 2009 - 06:31 PM

I made a code where the computer thinks of a random number between 1 and 100. Now i am trying to make a code where i input a number and the computer tries to guess it. this is only the beginning of the code so i have two questions. First and foremost is this how i would start off this kind of program and question number 2, when i try to compile it the compiler says " line 26 - expected primary-expression before ')' token" whats wrong with it? what is a primary expression. Im new at this programming language. line 26 is the line that says "while();system("pause")" here's the code:
// Computer guess the number
// Input a number and the comp will try and guess it

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
	cout << "\tWelcome to Computer Guess My Number\n\n";
	do
	{
		 int number1;
		 cout << "Enter your number: ";
		 cin >> number1;
		 
		 srand(time(0)); // seed random number generator
	
		 int theNumber = rand() % 100 + 1; // random number between 1 and 100
		 int tries = 0, guess;
		 
		 cout << "Computer guessed: " << theNumber;
	}
	while();system("pause")
  ;return 0;
}




Is This A Good Question/Topic? 0
  • +

Replies To: Error: expected primary-expression before ')' token

#2 fhsfootball53   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 27-January 09

Re: Error: expected primary-expression before ')' token

Posted 29 January 2009 - 06:37 PM

Any help would be greatly appreciated.
Was This Post Helpful? 0
  • +
  • -

#3 fhsfootball53   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 27-January 09

Re: Error: expected primary-expression before ')' token

Posted 29 January 2009 - 06:48 PM

Anyone?
Was This Post Helpful? 0
  • +
  • -

#4 Gloin   User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: Error: expected primary-expression before ')' token

Posted 29 January 2009 - 06:50 PM

Don't bump your threads, it will generally just make it take longer to get a reply as those who waited the longest get helped first and they're further down the list.

while();system("pause")

A while statements need some argument to evaluate to either true or false.

Just exchange the entire line for
cin >> number1;

it will promt the user for some input and then you just ignore the input.
Was This Post Helpful? 1
  • +
  • -

#5 fhsfootball53   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 27-January 09

Re: Error: expected primary-expression before ')' token

Posted 29 January 2009 - 06:52 PM

thanks!
Was This Post Helpful? 0
  • +
  • -

#6 Gloin   User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: Error: expected primary-expression before ')' token

Posted 29 January 2009 - 06:54 PM

no problemo!
Was This Post Helpful? 0
  • +
  • -

#7 Jayman   User is offline

  • Student of Life
  • member icon

Reputation: 423
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Error: expected primary-expression before ')' token

Posted 29 January 2009 - 09:06 PM

Modified title to be more descriptive of the problem.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1