for (int i = 0; i < index; i++) {
for (int k = index; k > 0; k--) {
std::cin >> array[i];
std::cin.get();
std::cout << "You've added " << array[i] << std::endl;
std::cout << "You have " << k << " slots left."
<< std::endl << std::endl;
}
}
and index was == 5
Keep the above in mind.
Before I added my
for (int k = index; k > 0; k--) {
it would increment until i has reached the array's max storage space (which in this case was 5)I'm trying to get k to decrement every time the user adds a new value into an array slot. Whatever I have up there does it successfully, but loops.
Anyways, after it successfully fills up the array with values in its slots, it will display them. If I am confusing you (which I probably am..sorry for the bad explanation) here is the whole program:
/*
* File: main.cpp
* Author: Admin
*
* Created on November 12, 2010, 8:50 PM
*/
#include <cstdlib>
#include <iostream>
/*
*
*/
int main(int argc, char** argv) {
int index;
int count;
int left;
/**
* Record how many slots there will be within the array itself
* @param argc
* @param argv
* @return
*/
std::cout << "How many slots do you want your array to have: ";
std::cin >> index;
std::cin.get();
/**
* Record the size of the array
* @param argc
* @param argv
* @return
*/
int array[index];
/*
*
*/
std::cout << std::endl << "Okay. You have " << index << " slots in your array";
std::cout << std::endl << "What would you like the values of your "
<< index << " slots to be: "
<< std::endl << std::endl;
/**
* Record all the wanted values for the slots
* @param argc
* @param argv
* @return
*/
for (int i = 0; i < index; i++) {
for (int k = index; k > 0; k--) {
std::cin >> array[i];
std::cin.get();
std::cout << "You've added " << array[i] << std::endl;
std::cout << "You have " << k << " slots left."
<< std::endl << std::endl;
}
}
/**
* Display everything
* @param argc
* @param argv
* @return
*/
for (int i = 0; i < index; i++) {
std::cout << array[i] << std::endl;
}
std::cin.get();
return 0;
}
Thanks.


Sign In
Create Account

Back to top









