#include <cstdlib>
#include <iostream>
#include <math.h>
usingnamespace std;
int main()
{
int num=0;
while(1)
{
cout<<"Enter a number to be cubed and then squared.\n";
cout<<"The number needs to be between 1 and 10\n";
while(1)
{
cout<<"Number is: ";
cin>>num;
if(num>=1 && num<=10)
break;
else
cout<<"Wrong number try again\n";
}//closing nested while
cout<<"\n\n";
cout<<num<<" squared is "<<pow(num,2);
cout<<"\n";
cout<<num<<" cubed is "<<pow(num,3);
int brk=0;
cout<<"\n\nrun again? 1=yes,2=no ";
cin>>brk;
if(brk==2);
break;
}//closing 1st while brace
return(0);
}
if there is another way to to do this, please tell me. and this is in WINDOWS XP if that helps.
everytime I execute it, it will go. but if i want to repeat the code it will not go again.
along with this.. what can I enter into my code to make so that if the user enters a letter, or something besides a number, so that it will not turn into an infinite loop?
EDIT: Btw, that means that it can't convert "cin.good" to a bool, and the second error means the ! (which needs a bool to the right) can't do it's operation (because cin.good isn't a bool). The final error means that it thinks you needed a ; at the end of the line because it thought it was a normal expression.
i am trying to make the program so if i enter in a character such as "a", it will not go into an infinite loop repeating my error message "Wrong Number try again"