Will show current code at bottom of thread, first of all huge thanks to anyone who helps out and even for reading thread. What happens when I run this is it lets me fill out first variable, but it runs all of the quizes without allowing the user to input a value and im really new to c++ and im sure im over looking something but I cant seem to find where im wrong. Point of program is to b simple DOS window to persons first and last name and the average of 5 quizzes a midterm and a final exam. Thanks again
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
short quiz1, quiz2, quiz3, quiz4, quiz5, quiztotal, midterm, final, avg;
int studentname;
//get student name
cout << "What is the students First and Last name? \n";
cin >> studentname;
//get quiz1
cout << "What is the first quiz grade? \n";
cin >> quiz1;
//get quiz2
cout << "What is the second quiz grade? \n";
cin >> quiz2;
//get quiz3
cout << "What is the third quiz grade? \n";
cin >> quiz3;
//get quiz4
cout << "What is the fourth quiz grade? \n";
cin >> quiz4;
//get quiz5
cout << "What is the fifth quiz grade? \n";
cin >> quiz5;
//get midterm
cout << "What is the midterm grade? \n";
cin >> midterm;
//get final
cout << "What is the final exam grade? \n";
cin >> final;
Yes. If you're dealing with a string, you should... use a string.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <cstdlib>
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
short quiz1, quiz2, quiz3, quiz4, quiz5, quiztotal, midterm, final, avg;
string studentname ;
//get student name
cout << "What is the students First and Last name? \n";
getline(cin, studentname) ;
// ...
Because you're asking for both the first and last name, you need to use getline. Using cin >> studentname would result in the extraction stopping at the first whitespace (and therefore only extracting the first name from the input stream.)
#include <cstdlib>
#include <iostream>
#include <string> // to use string and getline.
usingnamespace std;
int main()
{
// changed to float unless you really want to divide integers... ;)
float quiz1, quiz2, quiz3, quiz4, quiz5, quiztotal, midterm, final, avg;
string studentname;
//get student name
cout << "What is the students First and Last name? \n";
getline(cin, studentname);
//get quiz1
cout << "What is the first quiz grade? \n";
cin >> quiz1;
//get quiz2
cout << "What is the second quiz grade? \n";
cin >> quiz2;
//get quiz3
cout << "What is the third quiz grade? \n";
cin >> quiz3;
//get quiz4
cout << "What is the fourth quiz grade? \n";
cin >> quiz4;
//get quiz5
cout << "What is the fifth quiz grade? \n";
cin >> quiz5;
//get midterm
cout << "What is the midterm grade? \n";
cin >> midterm;
//get final
cout << "What is the final exam grade? \n";
cin >> final;
//get quiz total
quiztotal = quiz1 + quiz2 + quiz3 + quiz4 + quiz5;
//get overall average
avg = midterm + final + quiztotal / 7;
cout << "\n" << studentname << "'s average is: " << avg << endl;
// Dont use system(exit) if you can help it, bad habit.
cout << "\npress Enter to exit" << endl;
cin.ignore(99, '\n');
return 0;
}
Also if you did want to convert string to int or int to string. use stringstream in sstream header. With that you can load the int into the stream and spit it back out into a string. However, wont work if you are trying to put letters in an int.