473,396 Members | 1,836 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,396 software developers and data experts.

total of students by using two array ??

11
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, 185 views)
Feb 25 '15 #1

✓ answered by weaknessforcats

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

6 1355
Brilstern
208 100+
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 Expert Mod 8TB
What part is not working?
Feb 25 '15 #3
xtoma
11
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 Expert Mod 8TB
Before I offer a solution, do you know hoe to se a struct and a pointer?
Feb 26 '15 #5
xtoma
11
#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 Expert Mod 8TB
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.