I need to write a C++ code that will ask the user to enter either 1 or 2. If 1 is entered the program must count all even numbers from 0 to 100. (I got that part done) If 2 is entered you are suppose to prompt the user to enter their first, last, student id, and then print that information back for the user to see, if neither 1 or 2 is chosen, the program is to exit.

My problem is when i select 2, it will only let me enter the first name then it fills out the rest by itself. What did I do wrong?

#include <iostream>

using namespace std;

int main()
{
  int c,x=0;
  float nm1, nm2, sid;
 cout<<"Please enter either the number 1 or the number 2: "<<endl;
 cin>>c;
 
 if (c == 1)
 {
   while (x <= 100)
   {
         cout << x << endl;
         x = x + 2;
         }
    
 }
 else if (c == 2)
 {
     cout<<"Please enter your first name: ";
     cin>>nm1;
     cout<<"Please enter your last name: ";
     cin>>nm2;
     cout<<"Please enter your student id ";
     cin>>sid;
     cout<<"Your name is: "<< nm1<<nm2<< "and your student ID is: "<<sid<<endl;
   }
     else
     cout<<"you fail at following instructions, please try again"<<endl;
     system("pause");
}
float nm1, nm2, sid;

maybe the problem is

float

try

string nm1, nm2

remember to include

#include<string>
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.