Solved

Needs help in syntax

Posted on 2011-03-22
2
316 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is about my first experience with programming Arduino.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.

828 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