loop

nevermind
Last edited on
You need to store the number of questions somewhere - either as a constant or as a variable, then you can use a for loop:

1
2
3
4
5
for (int i=0; i < NUMBER_OF_QUESTIONS; i++)
{
   // display the question
  // get the answer
}

i made number of quesions equal to 4 and in the loop i asked 4 questions + took 4 answers but the loop doesnt stop
Last edited on
Can you show us the code?
Im sure its another dumb mistake




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

#include <iostream>
using namespace std;
int main()
{
int numofquestions=4; ans1; ans2 ; ans3; ans4;

  

for (int i=0; i <numofquestions; i++)
{
   cout<<"running?";
   cin>>ans1;
  cout<<"swimming?";
  cin>>ans2;
  cout<<"walking?";
  cin>>ans3;
  cout<<"football?";
      cin>>ans4;
     
      

}
}


int numofquestions=4; ans1; ans2 ; ans3; ans4;

You need to separate your variables with a comma, the semi colon only at the end.

int numofquestions=4, ans1, ans2 , ans3, ans4;
Topic archived. No new replies allowed.