Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Needs help in syntax

Posted on 2011-03-22
2
Medium Priority
?
321 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 2000 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

618 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