Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

got a problem is it with my if and else 1

Status
Not open for further replies.

ggreg

Programmer
Mar 9, 2001
201
US
all I am trying to do below is to add my s's and divid
them by 2 and adding my m's
and then adding the s's and m's together
but it is only givining me one person
can you tell me why??
thanks

#include<iostream.h>
#include<ctype.h>
//function prototypes
void main()
{
char what=' ';
char who[25]={0};
float scount=0;
float mcount=0;
float tcount=0;
cout<<&quot;Enter S for scout or M for any adults: &quot;<<endl;
cin>>what;
while (toupper(what !='x'))
{

cout<<&quot;Enter First name of person going on Campout: &quot;<<endl;
cin>>who;

cout<<&quot;Enter S for scout or M for any adults: &quot;<<endl;
cin>>what;
}

what=toupper(what);
if(what=='s')
scount=(scount+1)/2;
else
if(what=='m')
mcount=mcount+1;

tcount=scount+mcount;
cout<<what<<who<<endl;
cout<<&quot;Here is your tent count: &quot;<<tcount<<endl;



}
 
did you forget about what=toupper(what);

try insted:
if(what=='S')
scount=(scount+1)/2;
else
if(what=='M')
mcount=mcount+1;

instead of:
if(what=='s')
scount=(scount+1)/2;
else
if(what=='m')
mcount=mcount+1;

John Fill
1c.bmp


ivfmd@mail.md
 
John ,
I made those letters capitals but it did not change anything
my code printout on screen last name type and is giving me
0. Now I was hoping

what=toupper(what);
if the person enter a small s or a Big S that it would count
and make all the S big...yeah and I see that was your point
but now even with making that change it is still not showing
me everything that is enter and not doing the adding.

to you have any other thoughts or a better way to do
what I am trying to do?
 
First I now have it with your changes

but if I enter three events like
S .... sam
M ..... Bill
S ...... dave

then I end up getting
dave and 0
 
1. cin>> gets untill you press enter.
Instead of

S .... sam
M ..... Bill
S ...... dave

you should do at least

S press enter
.... sam press enter
M press enter
..... Bill press enter
S press enter
...... dave

John Fill
1c.bmp


ivfmd@mail.md
 
yes (I was just trying to show you some data)
 
By the way, pay attention on order of cins

....
cin>>who;
.....
cin>>what;
or

.....
cin>>what;
.....
cin>>who;
John Fill
1c.bmp


ivfmd@mail.md
 
Did you want to do the following?

#include<iostream.h>
#include<ctype.h>

void main()
{
char what=' ';
char who[25]={0};
float scount=0;
float mcount=0;
float tcount=0;

cout << &quot;Enter S for scout, M for adult, or any other key to quit: &quot;;
cin >> what;
what = toupper(what);

while((what == 'S') || (what == 'M'))
{
// update the counts
if(what == 'S')
++scount;
else if(what == 'M')
++mcount;

cout << &quot;Enter First name of person going on Campout: \n&quot;;
cin >> who;

cout<< &quot;What: &quot; << what << &quot; Who: &quot; << who << '\n';

cout << &quot;Enter S for scout, M for adult, or any other key to quit: &quot;;
cin >> what;
what = toupper(what);
}

// calculate and display the total
tcount = (scount / 2) + mcount;
cout<< &quot;Here is your tent count: &quot; << tcount << '\n';

cin >> what; // stops the console window from closing
}

 
Almost you got the calculation right to do what I want,
but what I was hoping for with
cout<<what<<who is a printout, (when done entering names)
of all names with a s or a m

CraigD thanks !!!!!!!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top