+ 1
How can I make a tally counter takes input equal 0 to reset to zero and other numbers to count
....
9 Answers
+ 2
No I want the user to enter a number
If number = 0 then reset
If number = 1 then count+=count
+ 2
Can you describe the idea of your code, the snippet in my previous response is adding <n> to <sum> when <n> is not zero. If <n> is zero, <sum> is resetted to zero again.
+ 2
Search on google about tally counter
I made my own simplest code
//simple Tally counter
#include <iostream>
using namespace std;
int main() {int c,i;
loop1 : c=0;
cout<<"count = "<<c<<endl;
//display what happens to c variable
loop2 : cin>>i;
cout<<"i = "<<i<<endl;
/*to explain
what happens to i variable
during loops*/
if (i != 1) goto loop1;
/*if so make count = 0
because we treat any number doesn't equal 1
as Reset button */
if (i = 1)
//we treat number 1 as count button
c=c+1;
//counter
cout<<"count = "<<c<<endl;
/*display the count
to be seen by user*/
if (c<9999) goto loop2;
//there is a limit for Tally counter
return 0;
}
+ 1
I'm not sure if I understand your question. What do you mean about "Tally counter"? Do you just want to count how many times function get called, and then use user input to reset counter variable?
+ 1
int n, sum { 0 };
while( std::cin >> n )
{
if( !n )
{
sum = 0;
continue;
}
sum += n;
}
std::cout << sum << "\n";
+ 1
I'm still a beginner
+ 1
I didn't studied that I 'm a student bro
+ 1
I had to ask, cause if this was an assignment, then usually it came with restrictions or rules.
Ok let's begin from you. Sketch your code, save it here in SoloLearn, and then share the saved code link here so I or others can check it out, and help you if you have difficulty.
I'm waiting for your code ...
https://www.sololearn.com/post/75089/?ref=app
0
Do you have to use goto and labels? I think we can also use a loop to do this.