I'm pretty new to c++. I've taken a couple of classes and I'm currently working on a program that lets the user input a list of activities for the day, and then check off each completed activity.
The user enters a number corresponding to the number of the activity to be checked off. If an activity has been completed, then it an "x" will be marked next to the activity.
I am able to check off each item one at a time, but I can't seem to check off multiple items.
What am I doing wrong? Or rather, what can I do differently? Thank you.
#include<iostream>
#include<string>
usingnamespace std;
int main(){
string input[100];
int count = 0;
int num[100];
int temp = 0;
int totalItems = 0;
int check[100];
cout << "Enter activities for the day. " <<
"Type 'done' when you are finished: " << endl;
for (count = 0; count < 100; count++) {
cin >> input[count]; // the user inputs a list of activities and types "done" all desired activities are listed
if (input[count] == "done") {
totalItems = count;
system("CLS");
cout << totalItems << " items entered. " << endl;
cout << "Alright, what have you completed?: " << endl;
for (count = 0; count < totalItems; count++) {
cout << input[count] << endl;
}
for (int y = 0; y < 100; y++) { // loop that allows the user to enter the number corresponding to the activity that they have completed
cin >> num[y];
temp = num[y] - 1;
system("CLS");
cout << totalItems << " items entered. " << endl;
cout << "Alright, what have you completed?: " << endl;
for (count = 0; count < totalItems; count++) {
if (count != temp) {
cout << input[count] << endl;
}
elseif ((temp = count)) { // when the input number matches the current count, the activity will show and "x" next to it.
cout << input[temp] << " x" << endl;
check[count] = 1;
}
elseif (num[count] = 1) { // if an activity has already been completed (checked), then the "x" will remain next to it.
cout << input[temp] << " x" << endl;
}
}
}
}
}
system("PAUSE");
}
You have single '=' where a double '==' should be. Lines 45 and 51. Also, you should use a do/while loop starting at line 16. I'm not sure of what some of your code is to accomplish, so I streamlined it a bit. Is this what you're trying to do??
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
string input[100];
int count = 0;
int num[100];
int temp = 0;
int totalItems = 0;
int check[100];
cout << "Enter activities for the day. " << endl <<
"Type 'done' when you are finished: " << endl;
do{
cin >> input[count]; // the user inputs a list of activities and types "done" all desired activities are listed
if (input[count] == "done")
{
totalItems = count;
system("CLS");
cout << totalItems << " items entered. " << endl;
cout << "They are: " << endl;
for (count = 0; count < totalItems; count++)
{
cout << count + 1 << " : " << input[count] << endl;
}
}
else
count++;
}while(count < 100 && input[count] != "done");
for (int y = 0; y < totalItems; y++) // loop that allows the user to enter the number corresponding to the activity that they have completed
{
cout << "Did you finish [ " << input[y] << " ] - ( Enter '1' for 'YES', or '0', for 'NO' )" << endl;
cin >> num[y];
}
//temp = num[y];
system("CLS");
cout << totalItems << " items entered. " << endl;
cout << "Alright, what have you completed?: " << endl;
for (count = 0; count < totalItems; count++) {
if (num[count] == 0) {
cout << input[count] << endl;
}
elseif (num[count] == 1) // when the input number matches the current count, the activity will show and "x" next to it.
{
cout << input[count] << " x" << endl;
}
}
cin >> temp; // Just to prevent screen from closing
}