English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

#include
using namespace std;

int main()
{
int Choice1=0;
char indicator='y';
int Ans=0;
if(indicator=='y')
{
cout<<"Please Enter a number from 1 to 10: "; cin>>Choice1;
cout< }
if(Choice1==1)
{
for(Choice1=1; Ans++;)
Ans+=Choice1;
cout< cout<<"You've Enter One, "< cout< cout< cout<<"Do you want to enter another value?";
cout<<"Enter y for yes, (n to end): "; cin>>indicator;
cout< cout< int Choice1=0;
}
if(Choice1==2)
{
for(Choice1=2; Ans++;)
Ans+=Choice1;
cout< cout<<"You've Enter One, "< cout< cout< cout<<"Do you want to enter another value?";
cout<<"Enter y for yes, (n to end): "; cin>>indicator;
cout< cout< }
cout< cout<<"Okay Bye\n\n";
return 0;
}

2007-01-25 21:14:53 · 4 answers · asked by capphire 2 in Computers & Internet Programming & Design

I'm trying to code out enter 1 to 10 if the user enter 4, programs reply "You entered 4" using "for" and "if"

2007-01-25 21:27:32 · update #1

To: Rawlyn, Dont REPLY RUBBISH. If i know i wouldn't be asking!

2007-01-25 21:28:55 · update #2

4 answers

I don't know what you're intention was with
for(Choice1=1; Ans++;)
Ans+=Choice1;

it should equal to
for(Choice1=1; Ans++;)
{Ans+=Choice1;}

and that looks like an endless loop.

2007-01-25 21:23:43 · answer #1 · answered by BataV 3 · 0 1

tested ok:-

---------------------------------------------------------------------------
int main()

{
int Choice1=0;
char indicator='y';
int Ans=0;

here12:

if(indicator=='y')
{
cout<<"Please Enter a number from 1 to 10: "; cin>>Choice1;
cout< }
if(indicator=='n')
{
goto here122;
}
if(Choice1>=1)
{
if(Choice1<=10)
{//for(Choice1=1; Ans++;)
//Ans+=Choice1;
cout< cout<<"You've Enter "< cout< cout< cout<<"Do you want to enter another value?";
cout<<"Enter y for yes, (n to end): "; cin>>indicator;
cout< cout< //int Choice1=0;
goto here12;
}
}
goto here12;

here122:
cout< cout<<"Okay Bye\n\n";
return 0;
}

mercury of love

2007-01-25 23:44:36 · answer #2 · answered by mercury of love 4 · 0 1

after
cout<<"Do you want to enter another value?";
cout<<"Enter y for yes, (n to end): "; cin>>indicator;
u should put a condition:
if(indicator=='y'){
cout<<"enter your number";
cin>>choice1;
}
or u can use a while loop instdead

2007-01-25 21:31:30 · answer #3 · answered by sam_f 4 · 0 1

Work it out for yourself!!!!

Does it compile? If not, there is something wrong with it. If it does compile, does it do what you want it to do? If not, there is something wrong with it.

In all seriousness, debugging and testing is as much a part of the programming process as writing the code itself. You need to learn to do this to be any good as a programmer - now is a perfect opportunity to get some practice!

2007-01-25 21:22:56 · answer #4 · answered by Anonymous · 0 1

fedest.com, questions and answers