Using loop to count number of entries


Posted on 16th Feb 2014 07:03 pm by admin

I'm writing a program that must ask user to type in numbers. After each entry, the program has to report the cumulative sum of the entries to date. The program should terminate when user enters 0.

The code:

Did you know?Explore Trending and Topic pages for more stories like this.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include #include int main() { using namespace std; char number; int count = 0; cout << "Enter a number: "; cin.get(number); while (number != '0') { ++count; cin.get(number); }; cout << "Total of " << count << " inputs.n"; system("pause"); // I'm aware that this way is very bad return 0; }

The problem is that if I enter 0, the program will say there's 0 input in total(correct).
If I type in 1 and the next number is 0, program will say there's 2 entries in total.
And if I type in 11 and 0, I get 3 entries in total.
But even more strange is that if you type 111 then 11 then 0 you get total of 7 entries.

No, the program must not show me the sum of all numbers entered, just how many entries you made, untill you typ in 0.
No comments posted yet

Your Answer:

Login to answer
300 Like 45 Dislike
Previous forums Next forums
Other forums

Multiple Pages
Hi. Im very new to php. I'm trying to create a basic login/registration page.

So I have a bas

upload image name with extension using php
hi frds..

<input id="file1" type="file" name="file[]" &a

drop-down with sub-category appear
Hello,

i know how to build a simple dro-down list, im looking for a code when im gonna choose

SCRIPT ERROR
Here is the CONTACT FORM I made for our website:

<form id="form1" name="

bind error during socket programming
i am kinda new to socket programming. wrote the below code for a server. but getting the bind error

Why does my php page download images over and over
Can anybody please explain to me why my php page keeps downloading the images and other items every

I need desperate help with this php code integrated with flash please
Can someone please help me with this php code which I have been stuck on for weeks . I am trying to

How would I protect......
I have a from, actually, a good amount of forms. How can I make it so you can't type the characters:

search query in mysql in php problem
my search query wont work, i know, that my codes are correct.please help

Code: [Select]&l

Object Interfaces
EDIT: Never mind, I just updated to php 5.

Hey all,

I'm currently experimenting with p

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash