Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This my C++ program. I can\'t make my name and my student id number appear in th

ID: 3774383 • Letter: T

Question

This my C++ program. I can't make my name and my student id number appear in the output instaed of typing it! In this program it asks me what is my name. I want my name and my studnet id number show up. I tried to replace  "Enter student name: " and put my name and the id but didn't work!

Here is my name and my student id Alex de Rossi 3390930

// Example program
#include <iostream>
#include <string>

using namespace std;

int main()
{
string name;
double hw1, hw2, hw3, hw4, q1, q2, q3, q4, m1, m2, f, avghw, avgq, fs; //initialize variables
cout << "Enter student name: " <<endl;
cin >> name; //read name
  
cout << "Enter homework 1 score: " << endl; //read homework grades
cin >> hw1;
cout << "Enter homework 2 score: " << endl;
cin >> hw2;
cout << "Enter homework 3 score: " << endl;
cin >> hw3;
cout << "Enter homework 4 score: " << endl;
cin >> hw4;

cout << "Enter quiz 1 score: " << endl; //read quiz grades
cin >> q1;
cout << "Enter quiz 2 score: " << endl;
cin >> q2;
cout << "Enter quiz 3 score: " << endl;
cin >> q3;
cout << "Enter quiz 4 score: " << endl;
cin >> q4;
  
cout << "Enter midterm 1 score: " << endl; //read midterm grades
cin >> m1;
cout << "Enter midterm 2 score: " << endl;
cin >> m2;
  
cout << "Enter final exam score: " << endl; //read final exam grade
cin >> f;


avghw = (hw1 + hw2 + hw3 + hw4)/4; //calculate homework average
  
avgq = (q1 + q2 + q3 + q4)/4; //calculate quiz average
  
fs = (avghw * 0.10) + (avgq * 0.10) + (m1 * 0.20) + (m2 * 0.20) + (f * 0.40); //calculate final grade
  
cout << "Student : " << name << endl; //print name
cout << "Final grade : " << fs << endl; //print final grade
  
if(fs >= 60) //if final grade >= 60, then print pass
cout << "Pass" << endl;
else //else print failed
cout << "failed" << endl;

  
}

Explanation / Answer

#include <iostream>
#include <string>
using namespace std;
int main()
{
string name="Alex de Rossi"; //your name has been saved in the string variable
int student_id=3390930;//your student id has been saved in the integer variable
double hw1, hw2, hw3, hw4, q1, q2, q3, q4, m1, m2, f, avghw, avgq, fs; //initialize variables
//cout << "Enter student name: " <<endl;
//cin >> name; //read name
cout<<name<<endl;
cout<<student_id<<endl;
  
cout << "Enter homework 1 score: " << endl; //read homework grades
cin >> hw1;
cout << "Enter homework 2 score: " << endl;
cin >> hw2;
cout << "Enter homework 3 score: " << endl;
cin >> hw3;
cout << "Enter homework 4 score: " << endl;
cin >> hw4;
cout << "Enter quiz 1 score: " << endl; //read quiz grades
cin >> q1;
cout << "Enter quiz 2 score: " << endl;
cin >> q2;
cout << "Enter quiz 3 score: " << endl;
cin >> q3;
cout << "Enter quiz 4 score: " << endl;
cin >> q4;
  
cout << "Enter midterm 1 score: " << endl; //read midterm grades
cin >> m1;
cout << "Enter midterm 2 score: " << endl;
cin >> m2;
  
cout << "Enter final exam score: " << endl; //read final exam grade
cin >> f;

avghw = (hw1 + hw2 + hw3 + hw4)/4; //calculate homework average
  
avgq = (q1 + q2 + q3 + q4)/4; //calculate quiz average
  
fs = (avghw * 0.10) + (avgq * 0.10) + (m1 * 0.20) + (m2 * 0.20) + (f * 0.40); //calculate final grade
  
cout << "Student : " << name << endl; //print name
cout << "Final grade : " << fs << endl; //print final grade
  
if(fs >= 60) //if final grade >= 60, then print pass
cout << "Pass" << endl;
else //else print failed
cout << "failed" << endl;
  
}

//code has been tested on g++ compiler

Note:I have commented my changes done in this program,please do ask in case of any doubt,Thanks.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote