Dear all,
I am new to this and I need ur help.
I have the following problem description

Write a C++ program that defines 3 arrays of integers a, b, c and 3 integers counts cnt_a, cnt_b , cnt_c. The program must then ask the user for the number of elements cnt_a, to insert in array a and then read in the corresponding element values is such a way that no value inserted more than once. Explain what changes are required to perform the same for array b.

I have made the following code. It works fine but I am not checking if the value inserted is the same.Also I havent initialized the other variables. Any help is much apreciated.

// pointers.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;


int main()
{
    int cnt_a=0; /* cnt_b, cnt_c;*/
    int *a;/**b,*c;*/
    bool valid=false;
    int i=0;

    cout <<"Please enter an integer number of elements for the array" << endl;
    cin >> cnt_a;
    a=new int[cnt_a];

    if (cnt_a>1) {
     valid=true; //set valid to false if value is less than 1
    }//end if statement

    while (valid){
    for (i; i<cnt_a; i++){
    cout <<"Now enter the " <<i+1<< " element of the array"<<endl;
    cin >> a[i];
    //Statements to check if the values of the elements are the same. If are the same prompt the user to enter again a number

    }//end for loop
    valid=false;
    }//end while loop


    return 0;
}

Thanks in advance!!!

Please use code tags [code] //code here [/code] next time. Hint, use an if statement to either increment your index (value doesn't match with other) or leave it the same (if it's a duplicate). You will probably need to shift your while loop around to reflect this (and base its condition on that index rather than a boolean).

I think first you need use conditional statements if, do you want keep arrays elements unique? use temporary variable for input then use statement for for checking values and finally copy temporary variable to array or repeat input through statement if.

I think first you need use conditional statements if, do you want keep arrays elements unique? use temporary variable for input then use statement for for checking values and finally copy temporary variable to array or repeat input through statement if.

Thanks, I have used your thinking and I was able to achieve what I wanted.

Thanks again

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.