#include<iostream>
#include<string>
using namespace std;
int main()
{
int n1;
int groupsize;
int total = 0;
int total1 = 0;
char userInput;
cout << "Please enter your total number of items \n";
cin >> n1;
cout << "Please enter the group size \n";
cin >> groupsize;
do
{
while(n1>0)
{ int currentGroup = groupsize;
for(int currentGroup = groupsize; n1 > 0 && currentGroup > 0; n1--, currentGroup--)
{
cout << "*";
}
cout << " ";
} cout << endl << "would you like to repeat? " << endl;
cin >> userInput;
switch (userInput)
{case 'Y' : case 'y' : return true;
case 'N' : case 'n' : return false;
}
cout << "please answer Y or N " << endl;
}while(true);
system("pause");
}
*/ Im trying to repeat the while and for loop again so the user can put in a fresh set of numbers again. But so far if I press y or n it exits the program.
But this is simple. Sure you've got do while working appropriate...but n1 is always going to evaluate to zero. You can thank the for loop for that.
Better code....
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
bool running = true; //It'll always run if set default to run.
while( running )
{
while(n1 > 0) //Rename n1 to something like 'number_of_items'
{
for( whatever )
{
}
//gotta reset n1 at some point so...
cout << "Please enter your total number of items \n";
cin >> n1;
}
cin >> exit?
switch on input
y: running = false;
n: running = true;
}
When I implement your way, It still only repeats " exit?" even if I press y or n it just repeats "exit". I'm looking to repeat the while loop and the for loop again. what it does is takes the input numbers and turns em into astrisks.
Example: user inputs 13 and groupsize 5.
the output is ***** ***** ***
after it does this I want to be able to input new numbers and a new set of groupsize after it asks the user if they want to continue.
Thank you for your help and yes my coding does suck... I'm learning from a book :c There is soo much I need to improve on.
Thanks for any amount of time you dedicate to helping a newbie!
You have a couple of problems.
After the while (n>0), you do int currentGroup = groupsize and you also do it in your for loop and there is another problem with the for loop.
Try: