c++ programme error

guys this is my programme
but im recieving some errors . can someone help me please

#include<iostream>


void generatequestion(int op,int num1 ,int num2)

{
switch(op)

{

case 0:

cout<<"\nHow much is "<<num1<<" + "<<num2<<"?";

break;

case 1:

cout<<"\nHow much is "<<num1<<" - "<<num2<<"?";

break;

case 2:

cout<<"\nHow much is "<<num1<<" * "<<num2<<"?";

break;

case 3:

cout<<"\nHow much is "<<num1<<" / "<<num2<<"?";

break;

}

}

int main()

{

clrscr();

int num1 , num2 , op , m;

float ans;

char messagecorrect[4][30] = {"Very Good!","Excellent!","Nice Work","Keep up the good work"};

char messagewrong[4][30] = {"No . Please try again ." , "Wrong . Try once more ." , "Dont give up!" , "No. Keep trying"};

while(ans!=1)

{

srand (time(NULL));

num1 = rand() % 10;

num2 = rand() % 10;

op = rand() % 4;

label1:

m = rand() % 4;

generatequestion(op,num1,num2);

cin>>ans;

if(op==0 && ans==(num1+num2))

cout<<messagecorrect[m];

else if(op==1 && ans==(num1-num2))

cout<<messagecorrect[m];

else if(op==2 && ans==(num1*num2))

cout<<messagecorrect[m];

else if(op==3 && ans==(num1/num2))

cout<<messagecorrect[m];

else

{

cout<<messagewrong[m];

if(ans!=1)

goto label1;

}

}

return 0;

}




closed account (E0p9LyTq)
im recieving some errors

The errors are?


PLEASE learn to use code tags, it makes reading your source MUCH easier.

http://www.cplusplus.com/articles/jEywvCM9/

HINT, you can edit your post and add code tags.
Why don't you get a book and learn modern C++ ?
The C++ Programming Language 4th ed by Bjarne Stroustrup
The C++ Standard Library: A Tutorial and Reference 2nd ed by Nicolai Josuttis

Your code wood look a bit more like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <string>
#include <ctime>

using namespace std;

enum class Operation
{
  Add,
  Sub,
  Mul,
  Div
};

void generatequestion(Operation op, int num1, int num2)
{
  switch (op)
  {
  case Operation::Add:
    cout << "\nHow much is " << num1 << " + " << num2 << "?";
    break;
  case Operation::Sub:
    cout << "\nHow much is " << num1 << " - " << num2 << "?";
    break;
  case Operation::Mul:
    cout << "\nHow much is " << num1 << " * " << num2 << "?";
    break;
  case Operation::Div:
    cout << "\nHow much is " << num1 << " / " << num2 << "?";
    break;
  }
}

int main()
{
  int num1 = 0, num2 = 0, m = 0;

  float ans = 0;

  string messagecorrect[] = { "Very Good!","Excellent!","Nice Work","Keep up the good work" };

  string messagewrong[] = { "No . Please try again ." , "Wrong . Try once more ." , "Dont give up!" , "No. Keep trying" };

  // should be called only once
  srand(unsigned(time(nullptr)));

  while (ans != 1)
  {
    num1 = rand() % 10;
    num2 = rand() % 10;
    m = rand() % 4;
    Operation op = static_cast<Operation>(m);
    generatequestion(op, num1, num2);
    cin >> ans;
    if (op == Operation::Add && ans == (num1 + num2))
      cout << messagecorrect[m];
    else if (op == Operation::Sub && ans == (num1 - num2))
      cout << messagecorrect[m];
    else if (op == Operation::Mul && ans == (num1*num2))
      cout << messagecorrect[m];
    else if (op == Operation::Div && ans == (num1 / num2))
      cout << messagecorrect[m];
    else
    {
      cout << messagewrong[m];  
      if (ans == -1)
        break;
    }
  }
  return 0;
}
Topic archived. No new replies allowed.