Dont know what the problem is? Need the program to tell if the answer is correct or incorrect

#include <stdio.h>
#define SECRET 17

int main(void)
{

int number_wanted;
int answer;
int number;

answer= SECRET*number;

printf("Doing the Exceriuses\n");
printf("How many exercises do you want to do:\n", number_wanted);
scanf("%i", &number_wanted);

while (number_wanted> 0)

{

printf("What is %i*%i?", SECRET, number, answer);
scanf("%i", SECRET, &number, &answer);

if(answer== SECRET *answer)

{
printf("Great work\n");
}


if(answer!=SECRET*number)
{
printf("You need a calculator!\n");
printf("You need a calculator");
}
}

return 0;
}
Last edited on
if(answer== SECRET *answer)


When is answer going to equal answer*17? Only when answer is zero. Is that what you wanted, or did you mean

if(answer== SECRET *number) ?

printf("What is %i*%i?", SECRET, number, answer);
Two %i but three values to be placed into those two %i. This doesn't seem right.

scanf("%i", SECRET, &number, &answer);
One %i, so you should provide one memory address. You've provided the number 17 and two memory addresses.

while (number_wanted> 0)
You never change number_wanted so this will run forever.


Use C++. Functions have been provided for you so you dno't have to mess around getting printf and scanf wrong. Here are some example functions.

1
2
3
4
5
6
7
8
9
#include <iostream>
int main()
{
  int number;
  const int SECRET = 17;
  std::cin >> number; // This will take an int from the console and put it into number. No need to get scanf wrong
  std::cout << "What is " << SECRET << " * " << number; // No need to get printf wrong
  return 0;
}

Last edited on
I'm using a basic C complier. I'm still having some trouble the program runs by giving me a multiplication problem but it does not output if the answer is right or wrong. Any suggestions???
I'm using a basic C complier. I'm still having some trouble the program runs by giving me a multiplication problem but it does not output if the answer is right or wrong. Any suggestions???
1
2
3
4
5
6
7
8
if (answer_from_user == actual_answer)
{
  printf("Correct");
}
else
{
  printf("Incorrect");
}
Last edited on
Topic archived. No new replies allowed.