C++ to Raptor flowchart

Mar 31, 2017 at 3:56am
How do I put this C++ program into a raptor flow chart?

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
  #include <iostream>

using namespace std;

//function to sets each array element to the correct answer according to the table
void setCorrectAnswers (int corrrectAnswers[10])
{
corrrectAnswers[0]=5;
corrrectAnswers[1]=22;
corrrectAnswers[2]=35;
corrrectAnswers[3]=0;
corrrectAnswers[4]=16;
corrrectAnswers[5]=28;
corrrectAnswers[6]=4;
corrrectAnswers[7]=3;
corrrectAnswers[8]=42;
corrrectAnswers[9]=51;

}

//function to asks the student to input their answers to each of the 10 questions
void inputAnswers(int givenAnswers[10])
{
for(int i=0; i<10; i++)
{
cout<<"please enter your answer for question #"<<(i+1)<<" ";
cin>>givenAnswers[i];
}
}

//function to it sets numright to the number of questions the student answered correctly.
int numberCorrect(int corrrectAnswers[10],int givenAnswers[10])
{
int numRight=0;
for(int i=0; i<10; i++)
{
if(corrrectAnswers[i]==givenAnswers[i])
numRight++;
}
return numRight;
}

int main()
{

//declaration
int corrrectAnswers[10];
int givenAnswers[10];
int numRight;

//calling functions
setCorrectAnswers(corrrectAnswers);
inputAnswers(givenAnswers);

//calculate number of right answers
numRight= numberCorrect(corrrectAnswers,givenAnswers);

//print grade
cout<<"Your quiz grade is "<<((float)(numRight/10.0f)*100.0f)<<"%"<<endl;
return 0;
}
Mar 31, 2017 at 2:53pm
What exactly is a "raptor flow chart"?

You really need to start consistently using some kind of indentation, your code as presented is hard to read.
https://en.wikipedia.org/wiki/Indent_style

Why the cast in line 59? And IMO, except is special circumstances, you should prefer double over float in this type of program.


Mar 31, 2017 at 3:11pm
Have you already learned what an initializer list does?
Instead of writing this:
1
2
3
4
5
6
7
8
9
10
11
int correctAnswers[10];
corrrectAnswers[0]=5;
corrrectAnswers[1]=22;
corrrectAnswers[2]=35;
corrrectAnswers[3]=0;
corrrectAnswers[4]=16;
corrrectAnswers[5]=28;
corrrectAnswers[6]=4;
corrrectAnswers[7]=3;
corrrectAnswers[8]=42;
corrrectAnswers[9]=51;

You can easily write:
 
int correctAnswers[count] = {val1, val2,...,valCount};

Note that this has to be done when declaring the array, so the following is invalid:
1
2
int correctAnswers[10];
correctAnswers = {val1,val2,...,val10} //invalid, compiler will complain 
Topic archived. No new replies allowed.