//Subtraction program - Brian Story
#include <stdlib.h>
#include <iostream>
usingnamespace std;
int main() {
int a, b, c, d, score; //Setting a, b, c, and score as an integer.
score = 0; // Score is equal to 0, so it starts you from the beginning every time.
do // loop while score is less then 10
{
srand (time(NULL)); // generates random numbers based on the time.
a = rand() % 10 + 1; // Calculates a as a random number from 1-10
b = rand() % 10 + 1; // Calculates b as a random number from 1-10
d = a - b; //Subtracts a and b and outputs the answer to d.
cout << a << " " << b << endl; // Shows user the random numbers generated
cout << a << " - " << b << " =?" << endl; // Same as above, but now asks for an answer.
cin >> c; // user inputs the answer as c
if (c==d) //compares the users answer and the real answer calculated above
cout << " Correct" << endl; // if its true tell the user its correct
score++; // adds 1 to score -- causes problem in program --
else // Complains that there is an expected ; before else
cout << " Incorrect" << endl; // if its true tell the user its not correct
} while (score<10); //Do whhile score is less then 10
cout << " You win!"; // Once the loop is complete tell the user he wins.
return 0;
}
The compile stops at else and claims that theres a missing ;
I am new and right now im assuming I used score ++ in an improper way, if I delete the scoree++ then it compiles fine, but I need to add one to score every time you complete a problem.
write a program asking user to chose p for pine, o for oak, or M for mahogany. show the price of the table pine - 100, oak- 225 and mahogany- 310 if user chooses any other than listed make price 0
write aprogram to for user to enter 2 integers and a character. if character is A add the two integers, if S, subtract the second from the first integer, if M, multiply. displat the result
#include <stdlib.h>
#include <iostream>
#include <ctime> // needed for time in your seed, or i need it for vc++
usingnamespace std;
int main() {
int a, b, c, d, score;
score = 0;
srand (time(NULL)); //moved out here so that it only seeds the srand once!
do
{
a = rand() % 10 + 1;
b = rand() % 10 + 1;
d = a - b;
cout << a << " " << b << endl;
cout << a << " - " << b << " =?" << endl;
cin >> c;
if (c==d)
{
cout << " Correct" << endl;
score++;
}
else
cout << " Incorrect" << endl;
} while (score<10);
cout << " You win!";
return 0;
}
this is also a good idea exercise that can be improved. for one, you can use rand a new number and check if it is even or odd, if odd "-" if even "+".