473,513 Members | 2,545 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to count numbers

2 New Member
#include <stdio.h>
int main()
{
float a[4]={.02, .05, .055, .01};

int i;
for (i=0; i<=300; i++)
if (a[i]>0.4 && a[i]<0.6) count++
printf("There are %d numbers between .4 and .6\n", some code???);
return 0;
}


I have to count how many numbers there are between .4 and .6 using c++ code and this is how far I got. There are actually 500 numbers in the program that I have to count, but to make things simple I put 4 numbers in there. Can anyone please tell me how to complete the program? Thanks!!
Sep 24 '06 #1
3 3509
risby
30 New Member
#include <stdio.h>
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3. float a[4]={.02, .05, .055, .01};
  4.  
  5. int i;
  6. for (i=0; i<=300; i++)
  7. if (a[i]>0.4 && a[i]<0.6) count++
  8. printf("There are %d numbers between .4 and .6\n", some code???);
  9. return 0;
  10.  
}


I have to count how many numbers there are between .4 and .6 using c++ code and this is how far I got. There are actually 500 numbers in the program that I have to count, but to make things simple I put 4 numbers in there. Can anyone please tell me how to complete the program? Thanks!!

You just have to declare the variable "count" as an integer just as you have with the variable "i" and you must initialize to zero before you start incrementing it in your loop. Then you just reference that variable where you currently have "some code???". Also, why is your loop condition i < 300 when you have 500 numbers to check?
Sep 24 '06 #2
gasfusion
59 New Member
printf("There are %d numbers between .4 and .6\n", count);

everything else should work fine
Sep 24 '06 #3
wangerman
2 New Member
Thanks everybody for your help! I got the program to work now. And sorry, I meant 300 numbers, not 500. Heres the program in case anyone will need it for their homework!


#include <stdio.h>
int main()
{
float a[300]={300 numbers in here};

int i;
int count=0;
for (i=0; i<=300; i++)
if (a[i]>0.4 && a[i]<0.6) count++;
printf("There are %d numbers between .4 and .6\n", count);
return 0;
}
Sep 24 '06 #4

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

Similar topics

2
6991
by: kumar mcmillan | last post by:
hi. I am using a pseudo "pivot table" SQL query to generate a report but I am totally stumped on why the COUNT() function isn't getting me the expected results and was wondering if anyone has some ideas... it is for a statistical report showing which lead source a member followed when creating a profile (i.e. CNN ad, Chicago Tribune ad,...
2
2579
by: DrewKull | last post by:
Ok ... so I'm looking at a query where im trying to show a bunch of columns counted up based on criteria ... So far i've been able to count all the rows up and show them ... and also count up one column based on the criteria (value = yes) ... but not both at the same time ... When i try it with all of them, all of them are either the same...
2
1754
by: bearophileHUGS | last post by:
itertools.count docs say: Does not currently support python long integers. Note, count() does not check for overflow and will return negative numbers after exceeding sys.maxint. This behavior may change in the future. But it seems it doesn't support negative numbers too:
4
2788
by: rdraider | last post by:
We have an inventory table (Items) that contains item_no and qty_on_hand fields. Another table (Item_Serial) contains serial numbers for any item that has serial numbers. If an item has 10 qty_on_hand, it should have 10 records in Item_Serial, one unique serial number for each item. I am trying to find items where the number of serial...
9
2757
by: MLH | last post by:
A mailing list table in its virgin state contained sequential, consecutive integers in an autonumber field (A97). I've deleted records throughout the table. Now I would like to identify each skipped number. Hmmm??? If I'd had a boolean field named , I could-a-check-marked it and they would-a-been much easier to count. How could I determine...
2
3059
by: Smokey Grindle | last post by:
any fast way to do this? I just need to check if if a string which could have a lot of characters in it if it has numbers and count the number of numbers in the string. thanks!
1
3606
by: zafm86 | last post by:
Hi everyone! I'm sure my problem is pretty easy to solve but I've been working on it for a long and my my brain is not working correctly anymore. I'm working with an AS400 and I mhave to do an "interface" in Access. It's like a little system to make a production plan. It must get information about part numbers, description, set where the part...
1
1906
by: crystalgal | last post by:
Help. I am using Excel to enter in daily numbers in worksheet 2. I want to use vb (w/in excel) to create a command button in worksheet 1. I want to enter a date in a cell and click the command button. I then want to use the date i entered into the cell to sum the total of numbers from worksheet 2 by filtering the numbers by the date. I want to...
14
3625
by: zufie | last post by:
I have to create a QA report regarding callers calling into a phone hotline. The report consists of many checkboxes such as: Did the IBCCP agency contact you? Yes/NO How many days passed before you heard from the agency? 1Week/2Weeks/3 or More Weeks Did you become an IBCCP client? Yes/NO/Dont Know
0
7270
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7178
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7565
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7543
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5704
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4759
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3255
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
817
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
473
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.