I would like that case 1: should display how many elements do i want, and that i can assign values to those elements. Mine because of the j++ goes infinite, so i can enter infinite values to infinite arrays.

How could i do this?

Cate elemente vrei sa adaugi: 3

Elementul[1] = 2
Elementul[2] = 2314
Elementul[3] = 635643

after entering the third value, it should display the sum(i can do that, but i`m having difficulties making the inputs from the "cin")

while (loop == 1)
    {
    
    cout << "1. Adaugare" << endl;
    cout << "2. Multiplicare" << endl;    
    cout << "3. Impartire" << endl;    
    cout << "4. Modulo" << endl;        
    cout << "5. TVA" << endl << endl;            
     
    cout << "Alege 1-5 (9 to exit): ";
    cin >> enter;
    
    switch(enter)    
    {
                     
                     case 1:
                          
                          cout << "Cate elemente vrei sa adaugi: ";
                          cin >> elements;
                          
                          for ( j=1; j<=i; j++)
                          {
                              cout << "Elementul [" << j << "]=";                                        
                              cin >> elements_added;
                              i++;
                              a[i] = elements_added;
                          }


                          
                          
                     break;

First things first, on lines 21, 25, 26... where did 'a[]' and 'i' come from??? Did you define them elsewhere? Are they properly initialized?

Second, why can't you just put an accumulator in your for loop then put the appropriate cout after the loop? Based on the segment you posted, you really don't even need to use an array. Just accumulate the values then display the total after the last one is entered.

And third: Please make it in English. It's a lot easier to read for us ;)

So here it is in english.

#include <iostream>
#include <stdlib.h>
#include <string>

using namespace std;

int main()
{
    string my_array[5];
    int enter;
    int elements = 0 , elements_added = 0;
    int cantitate, valoare;
    double tva = 1.19;
    int i = 0;
    int j = 0;
    int a[256];
    int loop = 1;

    while (loop == 1)
    {
    
    cout << "1. Add / Sum" << endl;
    cout << "2. Multiplication" << endl;    
    cout << "3. Divide" << endl;    
    cout << "4. Modulo" << endl;        
    cout << "5. VAT" << endl << endl;            
     
    cout << "Chose 1-5 (9 to exit): ";
    cin >> enter;
    
    switch(enter)    
    {
                     
                     case 1:
                          
                          cout << "Input nr. of elemets: ";
                          cin >> elements;
                          
                          for ( j=1; j<=i; j++)
                          {
                              cout << "Element [" << j << "]=";                                        
                              cin >> elements_added;
                              i++;
                              a[i] = elements_added;
                          }


                          
                          
                     break;
                     
                     case 2:
                          
                     break;
                     
                     case 3:
                          
                     break;
                     
                     case 4:
                          
                     break;  
                     
                     case 5:
                          
                          system("CLS");
                          
                          cout << "Quantity: ";
                          cin >> cantitate;
                          
                          cout << "Valoare BRUT: ";
                          cin >> valoare;
                          
                          cout << "Valoare totatala BRUT: " << cantitate * valoare << endl;
                          cout << "Valoarea TVA: " <<(valoare * cantitate * tva) - valoare * cantitate << endl;
                          cout << "Valoarea totala TVA: " << valoare * cantitate * tva << endl;
                          
                          system("PAUSE");
                          system("CLS");
                          
                     break;    
                     
                     case 9:
                          exit(0);
                          break;


    }
    }    
    
    
    system ("PAUSE");
    return 0;
}

1.) No need to be grouchy, there was nothing offensive about niek_e's post. This is an international website, it is a mistake for anyone to assume that everyone is fluent in their native language. In other words, ethnocentrism doesn't fly. Everyone here is at least familiar with English, they may not necessarily be fluent, but their familiar with it (it is one of only a few global languages). That's why it's part of the posting rules, even less-than-fluent English is still mostly understandable by all members.

2.) Please see my previous post. Specifically, the second part of it. There are a question and a suggestion there that you completely ignored during your little tantrum.

commented: he wasn't being grouchy. He did as requested -- politely -2

Oh common, I'm not ethnocentric, not even angry as you assume, I am learning C++ by small steps, and I thought that I can enter the values into the arrays. I know that it can be done with accumulator, but I was trying something different.

Thank you for your patience anyway!

Oh common, I'm not ethnocentric, not even angry as you assume, I am learning C++ by small steps, and I thought that I can enter the values into the arrays. I know that it can be done with accumulator, but I was trying something different.

Thank you for your patience anyway!

If that is in fact the case, I apologize. But I'm going to ask you to please be more careful about your wording. Voice inflection is an enormous part of spoken English (moreso than many, if not most, other languages). Written words can't carry inflection, and without it they can be interpreted several different ways if you're not careful. I'll leave it at that.

If you want to store the individual elements into an array for later reference that's fine. But in order to get the total you will need to create another loop. The second loop would then iterate through the elements of the array after you have finished entering them and accumulate the individual values. If you want to generate a running total, you'll need some sort of accumulator, that's just the way it is, you really can't escape it. The only difference is the block that contains it and where it is placed. Also, keep in mind that arrays start at element '0' not element '1'. This means that your array int a[256]; has elements [0, 255] not [1, 256] and the highest assignable element is (size-1). Because of that, it is advisable to place your statement i++; AFTER you assign the input value to the array element.

Got it working, thank you !

like this

case 1:
                                                    
                          system("CLS");
                          
                          cout << "Input nr. of elemets: ";
                          cin >> nr_elem;

                          for (int i=0; i < nr_elem; i++)
                          {
                              cout << "Element [" << i << "]=";
                              cin >> elements[i];
                              sum += elements[i];
                          
                          }
                              cout<<"Sum of elements: "<< sum << endl;
                                                                                      
                          system("PAUSE");
                          system("CLS");

                          
                          
                     break;

now when I try to use *= it always outputs me 0, why?

Really can't say without seeing what you've done in that part of the code. You are probably initializing to 0 then, as a result, every subsequent operation generates 0 because you are multiplying by 0. For multiplication and division, it may be advisable to initialize to 1.

Now ... everything is working fine, but I have some problems, clearing the stream, after an operation.

5*5 = 25

Next time it will 25*n ... I dont know how to do that.

#include <iostream>
#include <stdlib.h>
#include <string>
#include <math.h>

using namespace std;

int main()
{   
    string my_array[5];
    int enter;
    int elements[255];
    int nr_elem;
    int quantity, value;
    double vat = 1.19;
    int i = 0;
    int j = 0;
    int sum = 0;
    int multi = 1;
    int div_a, div_b;
    int divide;
    int a[256];
    int loop = 1;

    while (loop == 1)
    {
    
    cout << "1. Add / Sum" << endl;
    cout << "2. Multiplication" << endl;    
    cout << "3. Divide" << endl;    
    cout << "4. Modulo" << endl;        
    cout << "5. VAT" << endl << endl;            
     
    cout << "Chose 1-5 (9 to exit): ";
    cin >> enter;
    
    cout.flush();
    
    
    switch(enter)    
    {
                     
                     case 1:
                                                    
                          system("CLS");
                          
                          cout << "Input nr. of elemets: ";
                          cin >> nr_elem;

                          for (int i=0; i < nr_elem; i++)
                          {
                              cout << "Element [" << i << "]=";
                              cin >> elements[i];
                              sum += elements[i];
                          
                          }
                              cout<<"Sum of elements: "<< sum << endl;
                                                                                      
                          system("PAUSE");
                          system("CLS");
                          
                          
                     break;
                     
                     case 2:
                          
                          
                          system("CLS");
                          
                          cout << "Input nr. of elements: ";
                          cin >> nr_elem;
                          
                          for (int i=1; i <= nr_elem; i++)
                          {
                              cout << "Element [" << i << "]= ";
                              cin >> elements[i];
                              multi *= elements[i];
                          }
                          
                          cout << "Sum of multiplication: " << multi  << endl;
                          
                          system("PAUSE");
                          system("CLS");
                          
                          
                     break;
                     
                     
                     
                     
                     
                     case 3:
                          
                          system("CLS");
                          
                              cout << "Enter two elements " << endl;                          
                              cout << "Element 1: ";
                              cin >> div_a;
                              cout << "Element 2: ";
                              cin >> div_b;
                              
                              divide = div_a / div_b;
                              
                              cout << "Sum of division of " << div_a << " and " << div_b << " is " << divide << endl;
                              
                              system("PAUSE");
                              system("CLS");
                          
                          
                     break;
                     
                     case 4:
                          
                     break;  
                     
                     case 5:
                          
                          system("CLS");
                          
                          cout << "Quantity: ";
                          cin >> quantity;
                          
                          cout << "BRUT Value: ";
                          cin >> value;
                          
                          cout << "Total BRUT Value: " << quantity * value << endl;
                          cout << "VAT Value: " << (value * quantity * vat) - value * quantity << endl;
                          cout << "Total VAT Value: " << value * quantity * vat << endl;
                          
                          system("PAUSE");
                          system("CLS");
                          
                     break;    
                     
                     case 9:
                          exit(0);
                          break;


    }
    }    
    
    system ("PAUSE");
    return 0;
}

What exactly is your intent in the multiplication section? It's not very clear.

Do you want to multiply each resulting product by the next input or do you simply want to square each input and output the answer?

Yes, I want to multiply the next input, but it doesn't clear my memory so next time it will multiply with my last result. (The sum remains in the cache I think and I would like to empty it without exiting the program)

Yes, I want to multiply the next input, but it doesn't clear my memory so next time it will multiply with my last result. (The sum remains in the cache I think and I would like to empty it without exiting the program)

So you are trying to "square" the input while ignoring the previous result...? If that is the case, you can either simply put your multiplication operation in the output command and not save the result, or you can modify the statement that you are already using to do the multiplication (see below ---V).

Currently, you are using a multiplication compound assignment statement " multi [b]*=[/b] element[i] ". This statement multiplies the current value of the variable ('multi') by another value ('element') then stores the product back to the original variable ('multi'). What you need is something more like var = array[index] * array[index] .

Got it working, thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.