Solved

Needs help in syntax

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now