Please can you figure out the problem because it keeps say Invalid Credit when I chose 2?
Please can you figure out the problem because it keeps say Invalid Credit when I chose 2?
#include<iostream>
#include<string.h>
using namespace std;
struct student
{
int number;
string name;
int age;
string city;
}s[10];
struct module
{
int number;
string name;
string code;
int credit;
}m[10];
struct assessment
{
int number;
int marks1;
int marks2;
}a[10];
int index1 =0, index2=0, index3=0;
void StudentRegistration()
{
if(index1==10)
{
cout<<"No more data can be added"<<endl;
return;
}
string temp;
cout<<"Enter personal data"<<endl;
cout<<"Enter Student Number"<<endl;
cin>>s[index1].number;
cout<<"Enter Student Name"<<endl;
getline(cin, temp);
getline(cin,s[index1].name);
cout<<"Enter Age"<<endl;
cin>>s[index1].age;
cout<<"Enter city"<<endl;
getline(cin,temp);
getline(cin,s[index1].city);
index1++;
}
void ModuleEnrolment(int id)
{
if(index2==10)
{
cout<<"No more data can be added"<<endl;
return;
}
m[index2].number = id;
string temp;
int c;
getline(cin, temp);
cout<<"Enter Module 1 Name"<<endl;
getline(cin,m[index2].name);
cout<<"Enter Module 1 Code"<<endl;
getline(cin,m[index2].code);
cout<<"Enter Module 1 Credit"<<endl;
while(true)
{
cin>>c;
if(c!=15 && c!=30)
{
cout<<"Invalid Credit"<<endl;
}
else
{
m[index2].credit=c;
break;
}
}
index2++;
}
void StudentAssessment(int id)
{
if(index1==10)
{
cout<<"No more data can be added"<<endl;
return;
}
m[index3].number = id;
cout<<"Enter Module 1 marks"<<endl;
cin>>a[index3].marks1;
cout<<"Enter Module 2 marks"<<endl;
cin>>a[index3].marks2;
index3++;
}
void display(int id, int option)
{
if(option==1)
{
for(int i=0;i<index1;i++)
{
if(s[i].number == id)
{
cout<<"Personal Information"<<endl;
cout<<"Student Number "<<s[i].number<<endl;
cout<<"Student Name "<<s[i].name<<endl;
cout<<"Student Age "<<s[i].age<<endl;
cout<<"Student City "<<s[i].city<<endl;
return;
}
}
cout<<"Student ID not Found"<<endl;
}
else if(option==2)
{
for(int i=0;i<index2;i++)
{
if(m[i].number == id)
{
cout<<"Module Information"<<endl;
cout<<"Module 1 Name "<<m[i].name<<endl;
cout<<"Module 1 Code "<<m[i].code<<endl;
cout<<"Module 1 Credit "<<m[i].credit<<endl;
return;
}
}
cout<<"Student ID not Found"<<endl;
}
else if(option==3)
{
for(int i=0;i<index3;i++)
{
if(s[i].number == id)
{
cout<<"Assessment Information"<<endl;
cout<<"Module 1 marks "<<a[i].marks1<<endl;
cout<<"Module 2 marks "<<a[i].marks2<<endl;
return;
}
}
cout<<"Student ID not Found"<<endl;
}
}
int main()
{
cout<<"**************************************"<<endl;
cout<<"*Welcome to Student Management System*"<<endl;
cout<<"**************************************"<<endl;
int choice;
while(true)
{
cout<<"1- Student Registration"<<endl;
cout<<"2- Module Enrollment"<<endl;
cout<<"3- Student Assessment"<<endl;
cout<<"4- Search Student"<<endl;
cout<<"5.Exit"<<endl;
cout<<"Enter your choice (1-5): "<<endl;
cin>>choice;
if(choice == 1)
{
StudentRegistration();
cout<<"Student Information is added"<<endl;
}
else if(choice == 2)
{
int id;
cout<<"Enter Student ID: "<<endl;
cin>>id;
ModuleEnrolment(id);
cout<<"Modules Enrolled"<<endl;
}
else if(choice == 3)
{
int id;
cout<<"Enter Student ID: "<<endl;
cin>>id;
StudentAssessment(id);
cout<<"Assessment Added"<<endl;
}
else if(choice == 4)
{
int id,option;
cout<<"Enter Student ID: "<<endl;
cin>>id;
cout<<"Enter search Option"<<endl;
cout<<"1.Personal data search"<<endl;
cout<<"2.Module Search"<<endl;
cout<<"3.Assessment Search"<<endl;
cin>>option;
display(id,option);
}
else if(choice ==5)
{
break;
}
else
{
cout<<"Invalid Choice"<<endl;
}
}
}
Step by step
Solved in 2 steps