Solved

Needs help in syntax

Posted on 2011-03-22
2
314 Views
Last Modified: 2012-08-13
Hi guys: Can any one please help me in the syntax error ? Thanks.

#include <iostream>
#include <cmath>
#include <iomanip>
#include <ctime>
using namespace test;
int getRandomNumber(int lower, int upper)
int main()
{
      int smallest = 0;
      int largest = 0;
      int num1 = 0;
      int num2 = 0;
      int correctAnswer = 0;
      int userAnswer = 0;
      srand(static_cast<int>(time(0)));
      cout << "Smallest integer:";
      cin >> smallest;
      cout << "Largest integer:";
      cin >> largest;
      cout << endl;
      for (int x = 1; x < 6; x +=1)
      {
            num1 = getRandomNumber(smallest, largest);
            num2 = getRandomNumber(smallest, largest);
            correctAnswer = num1 + num2;
            cout << "What is the sum of " << num1 << "+" << num2 << "?";
            cin >> userAnswer;
            if(userAnswer == correctAnswer)
                  cout << "Correct!";
            else
                  cout << "Sorry, the correct answer is" << correctAnswer << ".";
            cout << endl << endl;
            system("pause");
            return 0;
            int getRandomNumber(int lower, int upper)
            {
                  int randInteger = 0;
                  randInteger = lower + rand() % (upper - lower +1);
                  return randInteger;
                  system("pause");
                  return 0;
}
0
Comment
Question by:mustish1
2 Comments
 
LVL 32

Accepted Solution

by:
phoffric earned 500 total points
ID: 35189314
This compiles and builds.
Look at //@@ for changes
#include <iostream>
#include <cmath>
#include <iomanip>
#include <ctime>
using namespace std; //@@

int getRandomNumber(int lower, int upper); //@@
int main()
{
   int smallest = 0;
   int largest = 0;
   int num1 = 0;
   int num2 = 0;
   int correctAnswer = 0;
   int userAnswer = 0;
   srand(static_cast<int>(time(0)));
   cout << "Smallest integer:";
   cin >> smallest;
   cout << "Largest integer:";
   cin >> largest;
   cout << endl;
   for (int x = 1; x < 6; x +=1)
   {
      num1 = getRandomNumber(smallest, largest);
      num2 = getRandomNumber(smallest, largest);
      correctAnswer = num1 + num2;
      cout << "What is the sum of " << num1 << "+" << num2 << "?";
      cin >> userAnswer;
      if(userAnswer == correctAnswer)
         cout << "Correct!";
      else
         cout << "Sorry, the correct answer is" << correctAnswer << ".";
      cout << endl << endl;
      system("pause");
      return 0;
   }
}
int getRandomNumber(int lower, int upper) //@@
{
   int randInteger = 0;
   randInteger = lower + rand() % (upper - lower +1);
   return randInteger;
   system("pause");
   return 0;
}

Open in new window

0
 

Author Closing Comment

by:mustish1
ID: 35189330
Thanks.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
A short article about problems I had with the new location API and permissions in Marshmallow
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question