hi , i had a problem with one of my programs im pretty sure everything is correct but when i run it it only asks me to input the last name but it would just print out the rest and not ask for any other input why is that? can someone help me what am i doing wrong.

the program is suposed to ask for the last name first name and 3 test scores for that person. then output the average of the test scores

#include <iostream>
using namespace std;
int main()
{
 int first;
 int last;
 int num1;
 int num2;
 int num3;

 cout<<" Enter your last name :";
  cin>> last;

 cout<<" Enter your last name :"<<endl;
 cin>>first;
 cout<<endl;

cout<< "enter three test scores :"<<endl;
 cin>> num1, num2, num3;
 cout<<endll;

 cout<< average of test scores is :"<<double((num1 + num2 + num3) /3.0)<<endl;

 return  0;
}

it doesnt ask for first name or to enter the test scores it just asks for the last name then compiles the rest and the average comes out to be this wierd negative number. can someone please help?

typo here

cout<<" Enter your last name :";
cin>> last;

cout<<" Enter your last name :"<<endl;
cin>>first;
cin>> num1, num2, num3;

should be

cin>> num1>>num2>>num3;

that should do it.

#include <iostream>
using namespace std;
int main()
{
 int first;
 int last;
 int num1;
 int num2;
 int num3;

 cout<<" Enter your last name :";
  cin>> last;

 cout<<" Enter your last name :"<<endl;
 cin>>first;
 cout<<endl;

cout<< "enter three test scores :"<<endl;
 cin>> num1, num2, num3;
 cout<<endll;

 cout<< average of test scores is :"<<double((num1 + num2 + num3) /3.0)<<endl;

 return  0;
}

you do have "enter last name" twice, that's why it's not asking for first name.

are you expecting an actual name from user input on first and last name? those are both ints and your program is going to crash when you try to get a string input into an int... you might want to fix that or do some sort of error checking

you also need to chain your cin. you can't just cin >> n1, n2, n3. Every time you call ">>" you are in effect calling a function that only has 2 parameters. cin >> n1 >> n2 >> n3 will fix that problem.

i got it to work thanxxxxxxxx alot 4 ur help :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.