473,378 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

stop the loop

I kept creating an infinite loop...
Intro level problem; should be easy




Given that two int variables, total and amount, have been declared, write a loop that reads integers into amount and adds all the non-negative values into total. The loop terminates when a value less than 0 is read into amount. Don't forget to initialize total to 0.
Sep 18 '06 #1
1 8462
Try this one.......

main()
{
int amount, total=0;

while(1)
{
printf("Entera number ");
scanf("%d", &amount);

if(amount < 0)
break;

total=total+amount;
}

printf("%d", total);
}
Sep 19 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jakub | last post by:
I have the following problem. Suppose I added a button to my worksheet and when user clicks the button a function starts. Now, as long as this function is running the worksheet is not active. The...
2
by: Steve Henderson | last post by:
I have really surprised myself and written a script that actually works! <grin>. As you will be able to tell, I'm really, really new to this scripting stuff... My script does a task and then sleeps...
16
by: deko | last post by:
I have a sub routine that searches the Outlook PST for a message sent to/from a particular email address. Obviously, this can take a long time when the PST contains thousands of messages. I'd...
14
by: S. Nurbe | last post by:
Hi, I have programmed a while loop. At the end of this loop I want to stop it until someone hit a key. When someone hits the right key the loop shall start again. Actually I thought this would...
4
by: Chip | last post by:
Can somebody explain to me why my process continues to run after I halt execution? This plays havoc with debugging. I expect to be starting a new instance at the beginning of a loop and the first...
14
by: electrician | last post by:
While running a program that exceeds the array limits it issues an alert. I want to then stop the program after filling in the output boxes with blanks. How do you stop the program? I have...
5
by: darthghandi | last post by:
I've created a class to listen to all interfaces and do a BeginAccept(). Once it gets a connection, it passes the connected socket off and stores it in a List. Next, it continues to listen for...
5
by: complexc | last post by:
I am having trouble figuring out how to stop from the loop using EOF. I need to use a while loop in main and use EOF to stop it. Can anyone guide me. This is part of the program I was asked to do:...
5
by: =?Utf-8?B?Sm9uYXRoYW4gU21pdGg=?= | last post by:
I have written a service, but it won't stop, Eventvwr reports the following: "Failed to stop service" The code is as follows: ============================================ Protected Overrides...
4
by: ravindarjobs | last post by:
hi...... i am using ms access 2003,vb6 i have a form. in that i have 2 buttons 1. start search 2 stop search when i click the "start search" button the fucntion SearchSystem() is called,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.