C please explain also | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

C please explain also

Write a program that will ask the user to continuously enter a number until such time that the entered value is not a number. #include <iostream> #include <iomanip> using namespace std; int main(){ int number; int sum = 0; int product = 1; int loopcount = 0; int totalnum = 0; std:: cout << "Enter total of numbers you want to add or multiply" <<endl; std:: cin>> std::setw(1) >> totalnum; std::cin.clear(); std:: cout<< "Enter"<<totalnum<< "numbers to add or multiply: " << endl; while (loopcount < totalnum){ std::cout << "Input a number or 'x' to stop: " << endl; std::cin>> std::setw(1)>> number; std::cin.ignore(); std::cin.clear(); sum+= number; product*= number; loopcount= loopcount + 1; if ( !( cin >> std::setw(1)>> number ) ) {break;} std::cin.clear(); std::cin.ignore(INT_MAX, '\n'); } std:: cout<<"The sum is :" <<sum<<endl; std:: cout<<"The product is :" <<product<<endl; return 0; } I have run this code it reads

2nd Oct 2021, 8:04 PM
Abhishek
Abhishek - avatar
1 Answer
+ 2
std::cin.ignore(INT_MAX ,...) Here your int max is showing undefined becz of you missed header files in which this method belong Just simply include this headerfile it will work fine #include<climits>
2nd Oct 2021, 8:15 PM
A S Raghuvanshi
A S Raghuvanshi - avatar