help

in this code you input the min required to pass and your grade but its not working correct

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
//Determines user's grade. Grades are Pass or Fail.
#include <iostream>
using namespace std;

char grade(int received_par, int min_score_par);
//Returns 'P' for passing, if received_par is
//min_score_par or higher. Otherwise returns 'F' for failing.

void instructions( );

int score, need_to_pass;
char letter_grade;
	
int main()
{
	instructions();
	

    if (letter_grade == 'P')
        cout << "You Passed. Congratulations!\n";
    else
        cout << "Sorry. You failed.\n";

    cout << letter_grade 
         << " will be entered in your record.\n";

    return 0;
}

char grade(int received_par, int min_score_par)
{
    if (received_par >= min_score_par)
        return 'P';
    else
        return 'F';
}

void instructions()

{
cout << "Enter your score"
         << " and the minimum needed to pass:\n";
    cin >> score >> need_to_pass;

    letter_grade = grade(score, need_to_pass);

    cout << "You received a score of " << score << endl
           << "Minimum to pass is " << need_to_pass << endl;
	
}
Last edited on
1
2
3
4
5
6
void instructions()
{
      cin >> score >> need_to_pass;  // 1 
      letter_grade = grade(need_to_pass, score); 
      
}


1 letter_grade, score and need_to_pass have not been defined, and the ones in the main function are invisible for this function

if you want to make these variables visible for instructions(), you have to send them as parameters (pointers or references) or make them global (not recommended)


Last edited on
Alright i fixed that problem but when i run the program it still doesn't work right
can you post your rewritten code?
Last edited on
yeah its the one on the top i switched somethings and it works fine now some of the variables where misplaced
Topic archived. No new replies allowed.