May 18, 2011 at 11:30pm May 18, 2011 at 11:30pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#include<iostream>
using namespace std;
short unsigned int choice = 0;
short unsigned int sss = 0;
void breakfast();
void lunch();
void snack();
void dinner();
void desert();
int main()
{
char answer;
short unsigned int i = 0;
cout<<"yes or no" <<endl;
cin>>answer;
if (answer = 'y' )
{
i = (i + 1);
}
else
{
i = (i + 2);
}
cout<<"yes or no" <<endl;
cin>>answer;
if (answer = 'y' )
{
i = (i + 1);
}
else
{
i = (i + 2);
}
cout<<i;
}
ignore those prototypes i just want to know how to pass down i? i mean if my first answer is y and my second answer is n, i want the cout to be 3 which is 1+2 but it is displaying 2 instead.
Actually i want that pass down thing to have global effect. E.g the code i have in main will be in one of the functions i call the function in main then display i.
Last edited on May 18, 2011 at 11:33pm May 18, 2011 at 11:33pm UTC
May 19, 2011 at 12:08am May 19, 2011 at 12:08am UTC
+1 Luc Lieber
@jimmy: look at lines 19, 30
May 19, 2011 at 12:27am May 19, 2011 at 12:27am UTC
No i don't want that.
ok here's what i want
int x = 0;
cout<<x;//0
x = x+1;
cout<<x//1
x = x+1
cout<<x//2 NOT 1 but 2 how i do that?
May 19, 2011 at 12:42am May 19, 2011 at 12:42am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#include<iostream>
using namespace std;
short unsigned int choice = 0;
short unsigned int sss = 0;
void breakfast();
void lunch();
void snack();
void dinner();
void desert();
int main()
{
char answer;
short unsigned int i = 0;
cout<<"yes or no" <<endl;
cin>>answer;
if (answer == 'y' ) // ==
{
i = (i + 1);
}
else
{
i = (i + 2);
}
cout<<"yes or no" <<endl;
cin>>answer;
if (answer == 'y' ) // ==
{
i = (i + 1);
}
else
{
i = (i + 2);
}
cout<<i;
}
Run this and enter first 'y' and then 'n'
Last edited on May 19, 2011 at 12:43am May 19, 2011 at 12:43am UTC