mastery 25

Strings are often used in programs to make easier the interaction with the user. When using strings in c++ it is really important to know how to decleare a variable and which libraries to use for the program. Strings, are basically information gathered by the program but intead of reading them as integers or numbers, they are text forms. Here is an example of how to use strings and which libraries to include:

<iostream>

<cstdlib>

<sstream>

using namespace std;

int triangles(){

  string T=”(,-*.*-,)”;

  int rows,cols,norows,i;

  cout<<“give me the number of rows”<<endl;

  cin>>norows;

  for(rows=1;rows<norows; rows++){

    for(cols=1; cols<=rows; cols++){

      cout<<T;

    }

    cout<<endl;

  }

for(rows=norows-1; rows>0; rows–){

  for(cols=1; cols<=rows; cols++){

    cout<<T;

  }

  cout<<endl;

}

}

int main(){

  triangles();

}

CC BY 4.0 mastery 25 by carlos green is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.