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.
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
usingnamespace 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);
}
elseif(letter == 't'){
score += test(num);
}
elseif(letter == 'a'){
score += assignment(num);
}
elseif(letter == 'l'){
score += lab(num);
}
elseif(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.
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.