Can someone help me convert this to a C++ program thanks .cpp import java.util.*
ID: 3620441 • Letter: C
Question
Can someone help me convert this to a C++ program thanks .cppimport java.util.*;
public class ex4_9 {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int count,i;
String name, name1="",name2="";
int score, score1=-999,score2=-999;
System.out.println("How many students do you have? ");
count=in.nextInt();
in.nextLine();
for(i=0;i {System.out.print("Enter student "+(i+1)+" name: ");
name=in.nextLine();
System.out.print("Enter student "+(i+1)+" score: ");
score=in.nextInt();
in.nextLine();
if(score>score1)
{score2=score1;
score1=score;
name2=name1;
name1=name;
}
else if(score>score2)
{score2=score;
name2=name;
}
}
System.out.println("Highest score: "+score1+" gotten by "+name1);
System.out.println("2nd highest score: "+score2+" gotten by "+name2);
}
}
Explanation / Answer
please rate - thanks #include<iostream>#include<string>
using namespace std;
int main()
{int count,i;
string name, name1="",name2="";
int score, score1=-999,score2=-999;
cout<<"How many students do you have? ";
cin>>count;
for(i=0;i<count;i++)
{cin.ignore(20,' ');
cout<<"Enter student "<<i+1<<" name: ";
getline(cin,name);
cout<<"Enter student "<<i+1<<" score: ";
cin>>score;
if(score>score1)
{score2=score1;
score1=score;
name2=name1;
name1=name;
}
else if(score>score2)
{score2=score;
name2=name;
}
}
cout<<"Highest score: "<<score1<<" gotten by "<<name1<<endl;
cout<<"2nd highest score: "<<score2<<" gotten by "<<name2<<endl;
system("pause");
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.