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

displaying number of students in each course

2
I'm using c++(language)
i need to display number of students doing each course, seemingly it displays the first number well but the second time i try it adds all the students doing all courses. here's the code below:
Expand|Select|Wrap|Line Numbers
  1.     {
  2.                     string str;
  3.                     int n, count = 0;
  4.  
  5.                 cout<<"Enter number of courses: ";
  6.                 cin>>n;
  7.  
  8.             for(int i=0; i<=n-1; i++)
  9.                     {
  10.                     cout<<"Enter course: ";
  11.                 cin>>str;
  12.  
  13.          for(int i=0; i<=str.size(); i++)    
  14.  
  15.          {         
  16.  
  17.          if(str == stud[i].cours)
  18.  
  19.          {
  20.  
  21. count++;
  22.  
  23. cout<<"Number of students doing "<<str<<" are "<<count<<endl;
  24.  
  25. }
  26.  
  27. }
  28.  
  29.  
  30. }
  31.  
  32. }
Oct 2 '19 #1
1 978
dev7060
636 Expert 512MB
From the snippet you have provided, it seems that a single count variable is being used. Different count variable needs to be used for each course to display distinct results.

Also, only the count++ part should be present in the body of if. After the if block, count can be printed.
Oct 12 '19 #2

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

Similar topics

4
by: Tim T | last post by:
Hi, I have a stored procedure executing a search and an asp.net page displaying the results in a datagrid. The datagrid has paging on it, I am using Visual Studio.NET and can't see any option...
16
by: sophie_newbie | last post by:
I have a list a little something like this: StringA StringC StringB StringA StringC StringD StringA ....
3
by: petermichaux | last post by:
Hi, Is there an internally assigned number for each JavaScript object that I can read? If so how would I do that? Thanks, Peter
4
by: General Fear | last post by:
I would like assign a number to each row in the table. The number can be row number. For example, the first record in the table can be number 1. I can do this thru VBA code. Can I do this via...
4
by: sscoder | last post by:
Hello. I am trying to find information on how to display calculations on the screen using .Net. I am not using a data grid. What I'm trying to do is display how many rows in a database and then do...
1
by: Amy G | last post by:
I have a table for survey questions named Q1 - Q30. I am trying to make a report based on reponse satisfied or disatisfied. The report needs to look like Q1 #Satisfied # Dissatisfied Q2...
1
by: Peter McGrath | last post by:
I have a table with one field a combo box with about 10 different options- (text from another table) for a client information table I want to make a report that gives me the actual number of each...
1
by: rbfullmer | last post by:
I'm new to C# and have scoured over the web for a solution. I have a string - a whole sentence that I want to assign a number to each letter, space, comma and period etc. So all "A's" will have the...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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:
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
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.