Ok I need to make a 3 part program thats made with c++. The first part is to write 10 number, and then program ask to ether repeat the number or to reapeat them reverse. Second part I need to make a program that ask for a word and later ask for a letter. Then the program will say that he found the letter to then ask if to tell you the first one or the last one. After you tell him what you want he will tell you the location where he found it. Last part is that he will ask for you to write a word or sentece to later ask you a word to then tell you all the locations that word appears. I starded something but I stupid brain won't work so yeah heres what I started:

#include <iostream>
#include <string>
using namespace std;

string ST1;
int I = 0, Idos, Ans;
int N[11];

int main()
{
    cout << "Escribe 10 numeros" << endl ;

    for (int I = 1; I <= 10; I++)
    {
        cout << I << ")"; cin >> N[I]; cout << "\n";
    }

    cout << "1)Repetirlos en orden O 2) Repetirlos alreves:";
    cin >> Ans;
    cout << endl;

    if (Ans == 1)
    {
        for (int I = 1; I <= 10;I++ )
        {
            cout << I << ")" << N[I] << "\n" << endl;
        }
    }
    if (Ans == 2)
    {
        for (int I = 10; I >= 0; I--)
        {
            cout << I << ")" << N[I] << "\n" << endl;
        }
    }

    system("pause");
}

Recommended Answers

All 3 Replies

Line 24 I would write as for (int I = 1; I <= 10;I=I+2 )
And as a side note: why are you reffering to a computer as a "he"?
It is just a bunch of copper, silicon, plastic and some other materials.

Or perhaps

for (int i = 1; i <= 10; i++)

or

for (int i = 1; i <= 10; i += 2)

depending on whether you need to increment by 1 or by 2. Also with i in lowercase because uppercase is typically used for consts.

I would worry about line 31 : for (int I = 10; I >= 0; I--)

When you read in the data

for (int I = 1; I <= 10; I++)
    {
        cout << I << ")"; cin >> N[I]; cout << "\n";
    }

You populate the value N[1], N[2]... etc. BUT you do not populate the value N[0] that is never set. But in line 31 you loop over I until and including I == 0. Thus the value printed will be undefined (i.e. anything!)

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.