I'm trying to write a c++ code that calculates a student's percentage grade. This is a sample of what the output should look like
Enter student's first and last name: John Smith Number of questions on the test: 40 Number of answers the student got correct: 31 John Smith 77.5%
Below is my own code. It allows me to enter the first line Enter student's first and last name: but then it just exits and this is the feedback return value 3221225620. please what am I doing wrong?
// Lab 3 percentage.cpp
// This program will determine the percentage
// of answers a student got correct on a test.
#include<iostream>
#include<string>
using namespace std;``
int main()
{
string name;
int numQuestions,
numCorrect,
studentName;
double percentage;
// Get student's test data
cout << "Enter student's first and last name: ";
cin >> studentName;
cout << "Number of questions on the test: ";
cin >> numQuestions;
cout << "Number of answers the student got correct: ";
cin >> numCorrect;
// Compute and display the student's % correct
percentage = (numCorrect / numQuestions) * 100;
// WRITE A STATEMENT TO COMPUTE THE % AND ASSIGN THE RESULT TO percentage.
cout << "The student: " << studentName << "has a test score of " << percentage << endl;
return 0;
}
Aucun commentaire:
Enregistrer un commentaire