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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why doesn't my traffic-counter work?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I'm learning my selfC-programming and i don't know what's wrong with my FIRST C-program. So i need bit help..


#include <stdio.h>




void main(void)

{
int sumab,sumvo,summw,sumta;
int saabs,volvos,bmws,toyotas;



printf(&quot;Traffic-counter\n\n&quot;);
printf(&quot;1 - Saab\n&quot;);
printf(&quot;2 - Volvo\n&quot;);
printf(&quot;3 - Bmw\n&quot;);
printf(&quot;4 - Toyota\n&quot;);
printf(&quot;0 - End session\n\n&quot;);
/*Printing instructions*/

printf(&quot;Give vehicle code:&quot;); /*Printing request for user*/

while (&quot;%d&quot;>=1&&&quot;%d&quot;<=4);
{
if (&quot;%d&quot;==1)
{
scanf(&quot;%d&quot;, &saabs);
sumab +=saabs;
}

else if (&quot;%d&quot;==2)
{
scanf(&quot;%d&quot;, &volvos);
sumvo +=volvos;
}

else if (&quot;%d&quot;==3)
{
scanf(&quot;%d&quot;, &bmws);
summw +=bmws;
}

else if (&quot;%d&quot;==4)
{
scanf(&quot;%d&quot;, &toyotas);
sumta +=toyotas;
}



if (&quot;%d&quot;==0)
{
printf(&quot;There were following vehicles:\n&quot;);
printf(&quot;&d Saabs\n&quot;,sumab);
printf(&quot;%d/2 Volvos\n&quot;,sumvo);
printf(&quot;%d/3 Bmws\n&quot;,summw);
printf(&quot;%d/4 Toyotas\n&quot;,sumta);
}


return 0;
}

 
Try the following Code and change it the way u want


#include <stdio.h>
#include <conio.h>


void main(void)
{ int sumab,sumvo,summw,sumta;
int saabs,volvos,bmws,toyotas;
textbackground(BLUE); textcolor(WHITE);
clrscr();

printf(&quot;Traffic-counter\n\n&quot;);
printf(&quot;1 - Saab\n&quot;);
printf(&quot;2 - Volvo\n&quot;);
printf(&quot;3 - Bmw\n&quot;);
printf(&quot;4 - Toyota\n&quot;);
printf(&quot;0 - End session\n\n&quot;);

/*Printing instructions*/

printf(&quot;Give vehicle code:&quot;); /*Printing request for user*/
while (1)
{scanf(&quot;%d&quot;, &saabs);
if (saabs > 5)
continue;
if (saabs < 0)
continue;
break;
}

if (saabs==1)
{sumab +=saabs;
}
else if (saabs==2)
{sumvo +=volvos;
}
else if (saabs==3)
{summw +=bmws;
}
else if (saabs==4)
{sumta +=toyotas;
}

if (saabs==0)
{// why this part ????????????????
printf(&quot;There were following vehicles:\n&quot;);
printf(&quot;1. Saabs\n&quot;,sumab);
printf(&quot;2. Volvos\n&quot;,sumvo);
printf(&quot;3. Bmws\n&quot;,summw);
printf(&quot;4. Toyotas\n&quot;,sumta);
}
else
printf(&quot;You selected option %d&quot;,saabs);
return;
} // main()

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top