I am trying to write a program that accepts a dollar rate and hte accepts a list of amounts adn converts tehm to Shekels and prints in a list with the sums.
HEre si my code:
It is giving em lots of errors and I am having no luck. I think strtok is the main problem but not sure how else to do it.
/*
Requests exchange rate and hen a list of dollar amount.
It then prints in a table the dollar and shekel amount and adds them up
*/
#include <stdio.h>
#include <string.h>
void main ()
{
/* defines maximum list of dollar amounts*/
#define MAXLINE 100
float rate;
float *dollar[MAXLINE]={0}; /*starts the array with a 0 so the rest of the array will be set to 0*/
int x=0;
float sumDollars,sumShekels;
int i=0;
char c;
int spaceCount=0;
/*starts the sums to 0*/
sumDollars=0.0;
sumShekels=0.0;
printf("Please input the current dollar exchange rate");
scanf_s("%f",&rate);
printf("Please input dollar amounts to calculate into Shekels. Return will end the list.");
/* reads the list of dollar amounts*/
while (spaceCount<=MAXLINE)
{
if ((c=getchar())==' ')
spaceCount++;
if ((c=getchar())=='\n')
}
for (i=0; dollar[i]=strtok(c," "), i++);
printf("$ \t IS\n");
printf("__ \t __\n");
/* Prints the list*/
for ( x=0; dollar[x]!= '\n'; x++)
{
sumDollars=sumDollars+dollar[x];
sumShekels=sumShekels+(dollar[x]*rate);
printf("%5.2f \t %5.2f", dollar[x], dollar[x]*rate);
}
getchar();
}