The program executes the first two statements then stops. Where am I going wrong
ID: 3623282 • Letter: T
Question
The program executes the first two statements then stops. Where am I going wrong?#include <iostream>
using namespace std;
int main()
{
int numNumber, num, count = 0, pos = 0, neg = 0, z = 0;
// ask user for a number of numbers
cout << "How many numbers will you enter? ";
cin >> numNumber;
for (count; count <= numNumber; count++)
{
cout << "Enter 1st number. ";
cin >> num;
count++;
if(count++ == 1)
{
cout << "Enter 2nd number. ";
cin >> num;
count++;
}
else if (count++ == 2)
{
cout << "Enter 3rd number. ";
cin >> num;
count++;
}
else if (count++ == 3)
{
cout << "Enter 4th number. ";
cin >> num;
count++;
}
else if (count++ == 4)
{
cout << "Enter 5th number. ";
cin >> num;
count++;
}
}
system ("PAUSE");
return 0;
}
Explanation / Answer
please rate - thanks
you don't say what your doing with the numbers, but I believe this is what you want
you were getting much to complicated
#include <iostream>
using namespace std;
int main()
{
int numNumber, num, count = 0, pos = 0, neg = 0, z = 0;
// ask user for a number of numbers
cout << "How many numbers will you enter? ";
cin >> numNumber;
for (count=1; count <= numNumber; count++)
{
cout << "Enter number "<<count<<": ";
cin >> num;
}
system ("PAUSE");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.