Need help with class average program!(Started something...)

Pages: 12
It is doing that because
-q 5 -a 8 -l 10 -t 2 -f
is not a filename. This one requires an actual file as arguement to run. So what you do is copy
-q 5 -a 8 -l 10 -t 2 -f
, open notepad, or gedit or kate or w/e and paste it in there. Save and provide that file as arguement when running the program.

If you saved it in a file called grade, then you do
./CA_Calculator grade
I cant use other files, I am only using command lines. No outside files. Just out of this program.
Okay, all I need help with is how to start this program.
How do I let the user start the program CA_Calculator with the command line:

./CA_Calculator -q 5 -a 8 -l 10 -t2 -f

Once they enter this the program then asks the user to enter the scores for 5 quizzes, 8 assignments and so on.

How can I do this? I know how to do the calculating the average part but its this begining using the command line and then having the progrom have the user enter in all the scores and then average the scores is what is confusing me? How do I store all this info so it can calculate? Anyone please show me what this program would look like.
Ok, then read my previous post and I mentioned in there a way to read input from command line using the <<< operator
Last edited on
I see what you are doing but I cant do it like that. You are right I am not arguing that. I just have to figure out a way to do it another way ha

My way also has to let the user put the order of those inputs in a random order. I dont think this program will work.
Thank you for your help
so now I have 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
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
 
using namespace std;

int main(int argc, char *argv[]){
	
	double score = 0;
	//passes the array of chars to a function that will check the arguments	
	check_args(argc, *argv, score);
	cout << "Final score: " << score << endl;
	print_class_avg(argc, score);
	


	return 0;

}

//Function that loops through each argument
void check_args(int arg_count, char arg_val[], double &score){

	int num;
	int sum;
	//Checks that the call has the minimum number of args
	if(arg_count >= 9){

		for(int i = 0; i < arg_count; i++){
				//should print out each argument
				//prints out each char of each arg, i.e. ".class_avg" would print out 
				// .
				//c
				//l
				//a
				//s
				//s etc etc
				cout << arg_val[i] << endl;
			}
		}
	}

//Function that checks a string sent into it.
void check_letter(char letter, int number, double &score)
{		
	int num = number - 48, x;
	if(letter == 'q'){
		score += quiz(num);
	}
	else if(letter == 't'){
		score  += test(num);
	}
	else if(letter == 'a'){
		score += assignment(num);
	}
	else if(letter == 'l'){
		score += lab(num);
	}
	else if(letter == 'f'){
		score += final();
	}
}


How can I get this to work in order for it to meet the qriterial above? I cant seem to get it to compile either, please help???
I really need help with the command line arguments part. Can someone show me how to get this program to let me

./CA_Calculator -q 5 -a 8 -l 10 -t 2 -f

and when this is entered I want the program then to prompt for 5 quiz scores, 8 assignment scores or however many they put in for each one. That is the major issue! Does anyone know how to do this????
Well, to do the job properly, you would need to interpret the data from the command-line to see whether it is valid, and if there are problems, output an informational message to the user before terminating the program.

You can use the strcmp() function in order to compare two character strings, and atoi() to convert a string to an integer, for example
1
2
3
4
5
6
7
8
9
10
11
    if (argc > 3) 
    {   
        if (!(strcmp(argv[1], "-q")) 
        {
            // first parameter was -q
            // next parameter should be a number
            int number = atoi(argv[2]);
            // number should be greater than 0
            etc...
        }
    }


Though if the parameters can be in any order, you would need more generalised code than this.

http://www.cplusplus.com/reference/cstring/strcmp/
http://www.cplusplus.com/reference/cstdlib/atoi/
First I have seen of that. Could you help me with getting this whole thing to work? What will the code have to look like to get the command line arguments working right? I just need a real working example of this first part with all the options and I can continue from there with error checking and whatever is left. I am just very stuck at this one point. Please.
*First time I have ever seen that.
Thank you for everyone helping, sorry to be a pain with these questions. Really, thank you for all the help.
Topic archived. No new replies allowed.
Pages: 12