How can I make a tally counter takes input equal 0 to reset to zero and other numbers to count | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can I make a tally counter takes input equal 0 to reset to zero and other numbers to count

....

28th Dec 2020, 8:07 PM
حازم الباز
حازم الباز - avatar
9 Answers
+ 2
No I want the user to enter a number If number = 0 then reset If number = 1 then count+=count
29th Dec 2020, 6:50 AM
حازم الباز
حازم الباز - avatar
+ 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.
29th Dec 2020, 6:53 AM
Ipang
+ 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; }
29th Dec 2020, 6:57 AM
حازم الباز
حازم الباز - avatar
+ 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?
28th Dec 2020, 9:07 PM
Michal Doruch
+ 1
int n, sum { 0 }; while( std::cin >> n ) { if( !n ) { sum = 0; continue; } sum += n; } std::cout << sum << "\n";
29th Dec 2020, 2:49 AM
Ipang
+ 1
I'm still a beginner
29th Dec 2020, 7:06 AM
حازم الباز
حازم الباز - avatar
+ 1
I didn't studied that I 'm a student bro
29th Dec 2020, 7:07 AM
حازم الباز
حازم الباز - avatar
+ 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
29th Dec 2020, 7:13 AM
Ipang
0
Do you have to use goto and labels? I think we can also use a loop to do this.
29th Dec 2020, 7:05 AM
Ipang