Hello,
I have made a program of "for loop",
I just want to take input from a user and if the numbers are float values, then the input should be accepted, also those input values should be entered in the "array" A[2];
I want the user to enter a number in the input "cin" and I have some questions,
Q.1 Should I keep the "cin" function before the for loop?
Q.2 When I enter the wrong value in the program, I want the program to take me back to the input field where it prompts the user to input the data or number ,can you pls help me with this?
Q.3 Have I placed the "break" statement at correct locations?
Can you pls help me with this? ThanksCode:#include<iostream> using namespace std; main() { float x=2.5; float y=7.5; float A[2]; float i; cout<<"pls enter a number"<< endl; cin>>i; for (int i=0; i<8;i++) { if(i==x) { cout<<"i="<<x<<endl; A[0]=i; } else cout<<"pls enter a number either 2.5 or 7.5"<<endl; if (i==y) { cout<<"i="<<y<<endl; A[1]=i; } else cout<<"pls enter a number either 2.5 or 7.5"<<endl; break; } system("pause"); }