Creating a Calculator

Hello

I am trying to create a type of calculator in my webpage that is sort of like a GPA calculator but a bit different. I am not sure how exactly to explain it but I do have a formula in excel which is how it works. I am wondering if there is anywhere to transfer the formula and the way it works from excel into my code so I can have it on my webpage. If anyone knows how to do this or if it is possible please let me know. Thanks!
... I do have a formula in excel ...
can we see it?
yea so basically how it works in excel its 's the first column of numbers is the percentage the assignment is worth out of 100
the second column of numbers is what you got
the third column of numbers is what you got * (the amount it’s worth/100)
then you get the sum of the third column and that’s your grade in the class

so the formula has like 2 inputs so its like the sum of (each component*(percentage the component is worth/100))

it’s dependent on how many components there are and how much it’s worth

So i am trying to make that into a webpage thats like easy to use for this school thing I'm doing.
If the rows of the first col sum to 100, then simply the sum of the rows of the second col would also be what student gets out of 100
Okay ya makes sense. How would i do that. like what do i have to put in the code? I'm pretty new to all this
what do i have to put in the code?

that'll depend on what container you decide to store the scores in:
Using C-style (dynamic) array
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

int main()
{
    std::cout << "How many components does the assignment have? \n";
    size_t num{};
    std::cin >> num;//input validation techniques: http://www.cplusplus.com/forum/beginner/206234/
    int* scores = new int[num];//allocate memory for dynamic array to hold scores
    int sum{};
    for (size_t i = 0; i < num; ++i)
    {
        std::cout << "Enter the score for component " << i + 1 << " of " << num << "\n";
        std::cin >> scores[i];
        sum += scores[i];
    }
    std::cout << "Total score out of 100: " << sum << "\n";
    delete [] scores;//release the allocated memmory 
}

Using std::vector
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <vector>

int main()
{
    std::cout << "How many components does the assignment have? \n";
    size_t num{};
    std::cin >> num;
    std::vector<int> scores(num);
    int sum{};
    for (size_t i = 0; i < num; ++i)
    {
        std::cout << "Enter the score for component " << i + 1 << " of " << num << "\n";
        std::cin >> scores[i];
        sum += scores[i];
    }
    std::cout << "Total score out of 100: " << sum << "\n";
    //http://stackoverflow.com/questions/965401/c-memory-management-and-vectors
    //http://stackoverflow.com/questions/10366474/where-does-a-stdvector-allocate-its-memory
}

Last edited on
Okay sweet alright. I am trying to use that but I'm running into trouble because I tried putting it in the style sheet but there are a lot of different containers and they all have different numbers on them so I am not sure which one to put it in. Does it go in the Java Script or just into the index instead maybe?
Topic archived. No new replies allowed.