vendredi 21 août 2015

I want to have an if function in the middle of a cout statement [on hold]

This is my first post I apologise in advance for any mistakes with my question.

I am trying to create code that ask for user input and goes to a function according the input. I understand how do that perfectly fine, I have run into an issue with

having an if function in a cout statement.

What I want is to out put "i) array[i], i) array[i] etc..."

where i have a for loop, that outputs i as 1, then 2, then 3, then 4 etc...

and the array represents a text which leads to the corresponding calculator

but the "i" in the if statement:

if (i % 5 = 3) {
            cout << endl;

}`

gives an error saying: "int i Error: Expression must be a modifiable Ivalue"

Here is my full code for the cout process. It's all I have so far.

    #include <iostream>
#include <ostream>
#include <vector>
#include <string>

using namespace std;


string choices[10] =
{ "cos(x)", "sin(x)", "tan(x)", "atan2(y, x)",
"sqrt(x)",  "x^y", "|x|", "floor(x)", "ceil(x)", "Exit" };

int main(){

    for (int i = 0; i < 10; ++i) {
        int j = i;
        cout << i << ")" << choices[i]; 
        if (i % 5 = 3) {
            cout << endl;
        }
    }

    int iPause;
    cin >> iPause;
    return (0);

}

Note: I do have this running but it prints in one line, I want to have an endl; every 3rd option. Hence the i % 5 = 3.

Aucun commentaire:

Enregistrer un commentaire