Solved

Needs help in syntax

Posted on 2011-03-22
2
319 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Six Sigma Control Plans
Progress

729 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