473,473 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

total of students by using two array ??

11 New Member
my program should display each day of the week the number of students attended to the class and show me the total which day 30 students were present in the class specific the day by using searching
i don't know if my program is true or not
can you give me some hints ..


.....


#include<iostream>
using namespace std;
int main()
{
int c=0,pos=-1,i,n=5,x;
int day[15];
bool found=false;

cout<<"please enter attendsin of student in array ";
for(i=0;i<n;i++)
cin>>day[i];

cout<<"please searching of day on which 30 students werw present in the class :";
cin>>x;



while(c<n&&!found)
{
if(day[c]==30)
{
pos=c;
found=true;
}
else
c++;
}
if(found)
cout<<x<<" is found in location "<<pos<<endl;
else
cout<<x<<" is not found "<<endl;
Attached Files
File Type: pdf g (1).pdf (114.3 KB, 187 views)
Feb 25 '15 #1
6 1358
Brilstern
208 New Member
xtoma,

Please use code tags to properly format your code. It makes it easier to understand and read for those that would like to help. Example:

[ CODE ]
Remove the spaces around the tag to make this look better.
Function
{
if(x>1)
{
Do x
}

}

[ /CODE ]

Expand|Select|Wrap|Line Numbers
  1.  
  2. This looks better.
  3. Function
  4.   {
  5.     if(x>1)
  6.       {
  7.          Do x
  8.       }
  9.  
  10.   }
  11.  
  12.  
Feb 25 '15 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
What part is not working?
Feb 25 '15 #3
xtoma
11 New Member
well, i want to execute program by using binary search. two correlation array ,so that it appears to me that number of days and number of attendees each day and exact day on which was attended by 30 students ,so it may be monday or sunday .


array[attendees]
array[days]

like this
Feb 25 '15 #4
weaknessforcats
9,208 Recognized Expert Moderator Expert
Before I offer a solution, do you know hoe to se a struct and a pointer?
Feb 26 '15 #5
xtoma
11 New Member
#include<iostream>
using namespace std;
int main()
{
int c=0,pos=-1,i,n,x;
int day[i];
int attended[i];

cout<"please,enter the number of element in array";
cin>>n;
cout<<"please,enter week days";
for(i=0;i<=n;i++)
cin>>day[i];
cout<<"The number of students in every day in the week";
for(i=0;i<=n;i++)
cin>>attended[i];
cout<<"enter searching item";
cin>>x;

bool found =false;
while(c <n&&!found)
{
if(day[c]==x)
{
pos=c;
found=true;
}
else
c++;
}

if (found)
cout<<x<<"is found in location"<<endl;
else
cout<<x<<"is not found"<<endl;
system("pause");
}
Feb 27 '15 #6
weaknessforcats
9,208 Recognized Expert Moderator Expert
This code:

Expand|Select|Wrap|Line Numbers
  1. int day[i];
  2.  
is invalid because the compiler does not know the number of elements for the array. The number of elements must be known at compile time. The value of the variable i won't be known until run time. You have to code something like:

Expand|Select|Wrap|Line Numbers
  1. int array[5];
If you really need to create the array at run time with i elements, then you use the malloc() function:

Expand|Select|Wrap|Line Numbers
  1. int* array = malloc(i * sizeof(int)); 
You might read: http://bytes.com/topic/c/insights/77...rrays-revealed
Feb 28 '15 #7

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

Similar topics

1
by: Rvenkatesh | last post by:
How to use array string in C#.Net to compare and replace characters between strings using function.
4
by: Rob | last post by:
I haven't a clue how to accomplish this. All the data is in one table. The data is stored by registration date and includes county and number of students brokne out by grade. Any help...
1
by: nel | last post by:
hi.. i want to know how to insert data using array in mysql where the data stored in field given? this field_name i taken from database.... thanks a lot...
2
by: palani12kumar | last post by:
Hi i've implemented a linear Queue using array. But i've been struck up with a doubt!!!!! Let me tell my problem with an example so that it can be clear. Size of the Queue(array) is 5. im...
1
shoonya
by: shoonya | last post by:
i am using array as a data type in my db .... ( sequence integer ) ; and it stores a value let {1,2,3,4,5}
1
by: r786amesh | last post by:
Hello Everybody, My question is I want to display Nested gridview footer total by using javascript. its very urgent pls help me... thnx ramesh
1
by: procris99 | last post by:
I'm having ALOT of trouble understanding this (C++)..and i don't think i'm even close to getting this right. Please help. The problem reads as follows: Use a one dimensional array to solve. A...
2
by: berrylthird | last post by:
This question was inspired by scripting languages such as JavaScript. In JavaScript, I can access members of a class using array syntax as in the following example: var myInstance:myClass = new...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.