Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Sum Multiple Value At a Time

Sum Multiple Value At a Time

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++tutorialcareerlearning
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mr Anup Roy
    wrote on last edited by
    #1

    Hi, I am a beginner in C++. Today my first program is summed two value. Question: Write a program that inputs the number of hours that an employee works and the employee wage. Then display the employee gross pay(Be sure promote to input). I have a question here I input two value and calculate their result and display, but I want to input more than two value. How to input more than two value and calculate them?

    #include
    using namespace std;
    int main()
    {
    int i, m, j, n, k, l;
    cout <<"Enter Your Work Hour:.\n";
    cin >>i >>m;
    cout << "Enter Your Salary:.\n";
    cin >> k >> n;
    j = i+m;
    l = k+n;
    cout << "Your Total Work Hour is:" << j <

    J D 2 Replies Last reply
    0
    • M Mr Anup Roy

      Hi, I am a beginner in C++. Today my first program is summed two value. Question: Write a program that inputs the number of hours that an employee works and the employee wage. Then display the employee gross pay(Be sure promote to input). I have a question here I input two value and calculate their result and display, but I want to input more than two value. How to input more than two value and calculate them?

      #include
      using namespace std;
      int main()
      {
      int i, m, j, n, k, l;
      cout <<"Enter Your Work Hour:.\n";
      cin >>i >>m;
      cout << "Enter Your Salary:.\n";
      cin >> k >> n;
      j = i+m;
      l = k+n;
      cout << "Your Total Work Hour is:" << j <

      J Offline
      J Offline
      jeron1
      wrote on last edited by
      #2

      By 'more than two' do you mean a variable number of inputs, or a fixed number?

      "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

      M 1 Reply Last reply
      0
      • M Mr Anup Roy

        Hi, I am a beginner in C++. Today my first program is summed two value. Question: Write a program that inputs the number of hours that an employee works and the employee wage. Then display the employee gross pay(Be sure promote to input). I have a question here I input two value and calculate their result and display, but I want to input more than two value. How to input more than two value and calculate them?

        #include
        using namespace std;
        int main()
        {
        int i, m, j, n, k, l;
        cout <<"Enter Your Work Hour:.\n";
        cin >>i >>m;
        cout << "Enter Your Salary:.\n";
        cin >> k >> n;
        j = i+m;
        l = k+n;
        cout << "Your Total Work Hour is:" << j <

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        You'd need to use an array and a loop. Something like:

        int hours[5] = {0};
        for (int x = 0; x < 5; x++)
        {
        cout << "Enter hours worked for day " << (x + 1) << ": ";
        cin >> hours[x];
        }

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

        M 1 Reply Last reply
        0
        • J jeron1

          By 'more than two' do you mean a variable number of inputs, or a fixed number?

          "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

          M Offline
          M Offline
          Mr Anup Roy
          wrote on last edited by
          #4

          Variable number of input..

          J 1 Reply Last reply
          0
          • D David Crow

            You'd need to use an array and a loop. Something like:

            int hours[5] = {0};
            for (int x = 0; x < 5; x++)
            {
            cout << "Enter hours worked for day " << (x + 1) << ": ";
            cin >> hours[x];
            }

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

            M Offline
            M Offline
            Mr Anup Roy
            wrote on last edited by
            #5

            Hi David, I got it thanks for your help.

            1 Reply Last reply
            0
            • M Mr Anup Roy

              Variable number of input..

              J Offline
              J Offline
              jeron1
              wrote on last edited by
              #6

              In keeping with Davids theme, you could specify an array that's larger than you would ever need, and have the user enter the number of entries first, then setup an input loop based on that. Or setup a loop that runs the same number of times as your array size and have the user enter a value (like -1) that denotes the end of the data at which point you would exit the loop, then process the the data entered prior to the -1 entry.

              "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups