471,873 Members | 1,634 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,873 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 8337
Try this one.......

int amount, total=0;

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

if(amount < 0)


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

Post your reply

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

Similar topics

2 posts views Thread by Steve Henderson | last post: by
14 posts views Thread by S. Nurbe | last post: by
4 posts views Thread by Chip | last post: by
14 posts views Thread by electrician | last post: by
5 posts views Thread by =?Utf-8?B?Sm9uYXRoYW4gU21pdGg=?= | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by zermasroor | last post: by

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.