Question

How convert this c++ into C #include<iostream> #include <stdlib.h> using namespace std; void multiplication() { int...

How convert this c++ into C

#include<iostream>
#include <stdlib.h>
using namespace std;
void multiplication()
{
int num1;
int c, num2, ans;
cout<<"Enter difficulty level(1/2)\n";
cin>>c;
if(c==1)
{
num1= rand() % 10;
num2= rand() % 10;
cout<<"what is"<<num1 <<"*"<<num2<<"?\n" ;
cin>>ans
while(ans!=(num1*num2))
{
if(ans!=(num1*num2))
{
cout<< "No. Please try again.\n";
cout<<"what is"<<num1 <<"*"<<num2<<"?\n" ;
cin>>ans;
}
}
}
else if(c==2)
{
num1= rand() % 10+90;
num2= rand() % 10+90;
cout<<"what is"<<num1 <<"*"<<num2<<"?\n" ;
cin>>ans;
while(ans!=(num1*num2))
{
if(ans!=(num1*num2))
{
cout<< "No. Please try again.\n";
cout<<"what is"<<num1 <<"*"<<num2<<"?\n" ;
cin>>ans;
}
}
}
}
void addition()
{
int num1;
int c, num2, ans;
cout<<"Enter difficulty level(1/2)\n";
cin>>c;
if(c==1)
{
num1= rand() % 10;
num2= rand() % 10;
cout<<"what is"<<num1 <<"+"<<num2<<"?\n" ;
cin>>ans;
while(ans!=(num1+num2))
{
if(ans!=(num1+num2))
{
cout<< "No. Please try again.\n";
cout<<"what is"<<num1 <<"+"<<num2<<"?\n" ;
cin>>ans;
}
}
}
else if(c==2)
{
num1= rand() % 10+90;
num2= rand() % 10+90;
cout<<"what is"<<num1 <<"+"<<num2<<"?\n" ;
cin>>ans;
while(ans!=(num1+num2))
{
if(ans!=(num1+num2))
{
cout<< "No. Please try again.\n";
cout<<"what is"<<num1 <<"+"<<num2<<"?\n" ;
cin>>ans;
}
}
}
}
void subtraction()
{
int num1;
int c, num2, ans;
cout<<"Enter difficulty level(1/2)\n";
cin>>c;
if(c==1)
{
num1= rand() % 10;
num2= rand() % 10;
cout<<"what is"<<num1 <<"-"<<num2<<"?\n" ;
cin>>ans;
while(ans!=(num1-num2))
{
if(ans!=(num1-num2))
{
cout<< "No. Please try again.\n";
cout<<"what is"<<num1 <<"-"<<num2<<"?\n" ;
cin>>ans;
}
}
}
else if(c==2)
{
num1= rand() % 10+90;
num2= rand() % 10+90;
cout<<"what is"<<num1 <<"-"<<num2<<"?\n" ;
cin>>ans;
while(ans!=(num1-num2))
{
if(ans!=(num1-num2))
{
cout<< "No. Please try again.\n";
cout<<"what is"<<num1 <<"-"<<num2<<"?\n" ;
cin>>ans;
}
}
}
}
void division()
{
float num1,num2;
int c;
float ans;
cout<<"Enter difficulty level(1/2)\n";
cin>>c;
if(c==1)
{
num1= rand() % 10;
num2= rand() % 10;
cout<<"what is"<<num1 <<"/"<<num2<<"?\n" ;
cin>>ans;
while(ans!=(num1/num2))
{
if(ans!=(num1/num2))
{
cout<< "No. Please try again.\n";
cout<<"what is"<<num1 <<"/"<<num2<<"?\n" ;
cin>>ans;
}
}
}
else if(c==2)
{
num1= rand() % 10+90;
num2= rand() % 10+90;
cout<<"what is"<<num1 <<"/"<<num2<<"?\n" ;
cin>>ans;
while(ans!=(num1/num2))
{
if(ans!=(num1/num2))
{
cout<< "No. Please try again.\n";
cout<<"what is"<<num1 <<"/"<<num2<<"?\n" ;
cin>>ans;
}
}
}
}
int question()
{   
int c, o,i;
cout<<" 1.Addition\n 2.Subtraction \n 3.Multiplication \n
4.Division\n 5.Random \n Enter your choice\n";
cin>>o;
switch(o)
{
case 1:
addition();
break;
case 2:
subtraction();
break;
case 3:
multiplication();
break;
case 4:
division();
break;
case 5:
i=rand() %4;
if(i==0)
{
addition();
break;
}
else if(i==1)
{
subtraction();
break;
}
else if(i==2)
{
multiplication();
break;
}
else if(i==3)
{
division();
break;
}
break;
}
return 1;
}
//Main function
int main()
{
int n;
char ch = 'y';
while(ch=='y')
{
n= question();
if(n==1)
cout<<"Very good!\n";
cout<<"Do you wish to continue(y/n)?\n";
cin>>ch;
}
return 0;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C Program:

#include<stdio.h>
#include <stdlib.h>
void multiplication()
{
int num1;
int c, num2, ans;
printf("Enter difficulty level(1/2)\n");
scanf("%d",&c);
if(c==1)
{
num1= rand() % 10;
num2= rand() % 10;
printf("what is %d*%d?\n",num1,num2);
scanf("%d",&ans);
while(ans!=(num1*num2))
{
if(ans!=(num1*num2))
{
printf("No. Please try again.\n");
printf("what is %d*%d?\n",num1,num2);
scanf("%d",&ans);
}
}
}
else if(c==2)
{
num1= rand() % 10+90;
num2= rand() % 10+90;
printf("what is %d*%d?\n",num1,num2);
scanf("%d",&ans);
while(ans!=(num1*num2))
{
if(ans!=(num1*num2))
{
printf("No. Please try again.\n");
printf("what is %d*%d?\n",num1,num2);
scanf("%d",&ans);
}
}
}
}
void addition()
{
int num1;
int c, num2, ans;
printf("Enter difficulty level(1/2)\n");
scanf("%d",&c);
if(c==1)
{
num1= rand() % 10;
num2= rand() % 10;
printf("what is %d+%d?\n",num1,num2);
scanf("%d",&ans);
while(ans!=(num1+num2))
{
if(ans!=(num1+num2))
{
printf("No. Please try again.\n");
printf("what is %d+%d?\n",num1,num2);
scanf("%d",&ans);
}
}
}
else if(c==2)
{
num1= rand() % 10+90;
num2= rand() % 10+90;
printf("what is %d+%d?\n",num1,num2);
scanf("%d",&ans);
while(ans!=(num1+num2))
{
if(ans!=(num1+num2))
{
printf("No. Please try again.\n");
printf("what is %d+%d?\n",num1,num2);
scanf("%d",&ans);
}
}
}
}
void subtraction()
{
int num1;
int c, num2, ans;
printf("Enter difficulty level(1/2)\n");
scanf("%d ",&c);
if(c==1)
{
num1= rand() % 10;
num2= rand() % 10;
printf("what is %d-%d?\n",num1,num2);
scanf("%d",&ans);
while(ans!=(num1-num2))
{
if(ans!=(num1-num2))
{
printf("No. Please try again.\n");
printf("what is %d-%d?\n",num1,num2);
scanf("%d",&ans);
}
}
}
else if(c==2)
{
num1= rand() % 10+90;
num2= rand() % 10+90;
printf("what is %d-%d?\n",num1,num2);
scanf("%d",&ans);
while(ans!=(num1-num2))
{
if(ans!=(num1-num2))
{
printf("No. Please try again.\n");
printf("what is %d-%d?\n",num1,num2);
scanf("%d",&ans);
}
}
}
}
void division()
{
float num1,num2;
int c;
float ans;
printf("Enter difficulty level(1/2)\n");
scanf("%d",&c);
if(c==1)
{
num1= rand() % 10;
num2= rand() % 10;
printf("what is %d/%d?\n",num1,num2);
scanf("%d",&ans);
while(ans!=(num1/num2))
{
if(ans!=(num1/num2))
{
printf("No. Please try again.\n");
printf("what is %d-%d?\n",num1,num2);
scanf("%d",&ans);
}
}
}
else if(c==2)
{
num1= rand() % 10+90;
num2= rand() % 10+90;
printf("what is %d/%d?\n",num1,num2);
scanf("%d",&ans);
while(ans!=(num1/num2))
{
if(ans!=(num1/num2))
{
printf("No. Please try again.\n");
printf("what is %d-%d?\n",num1,num2);
scanf("%d",&ans);
}
}
}
}
int question()
{   
int c, o,i;
printf(" 1.Addition\n 2.Subtraction \n 3.Multiplication \n 4.Division\n 5.Random \n Enter your choice\n");
scanf("%d",&o);
switch(o)
{
case 1:
addition();
break;
case 2:
subtraction();
break;
case 3:
multiplication();
break;
case 4:
division();
break;
case 5:
i=rand() %4;
if(i==0)
{
addition();
break;
}
else if(i==1)
{
subtraction();
break;
}
else if(i==2)
{
multiplication();
break;
}
else if(i==3)
{
division();
break;
}
break;
}
return 1;
}
//Main function
int main()
{
int n;
char ch='y';
while(ch=='y')
{
n= question();
if(n==1)
printf("Very good!\n");
printf("Do you wish to continue(y/n)?\n");
scanf(" %c",&ch);
}
return 0;
}

if you like the answer please provide a thumbs up.

Add a comment
Know the answer?
Add Answer to:
How convert this c++ into C #include<iostream> #include <stdlib.h> using namespace std; void multiplication() { int...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • How to convert C++ code to C #include<iostream> #include <stdlib.h> using namespace std; void multiplication() {...

    How to convert C++ code to C #include<iostream> #include <stdlib.h> using namespace std; void multiplication() { int num1; int c, num2, ans; cout<<"Enter difficulty level(1/2)\n"; cin>>c; if(c==1) { num1= rand() % 10; num2= rand() % 10; cout<<"what is"<<num1 <<"*"<<num2<<"?\n" ; cin>>ans while(ans!=(num1*num2)) { if(ans!=(num1*num2)) { cout<< "No. Please try again.\n"; cout<<"what is"<<num1 <<"*"<<num2<<"?\n" ; cin>>ans; } } } else if(c==2) { num1= rand() % 10+90; num2= rand() % 10+90; cout<<"what is"<<num1 <<"*"<<num2<<"?\n" ; cin>>ans; while(ans!=(num1*num2)) { if(ans!=(num1*num2)) { cout<< "No....

  • #include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int...

    #include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int num1, num2, result; while(ch == 'Y'){ cout << "Enter first number: "; cin >> num1; while(1){//for handling invalid inputs if(cin.fail()){ cin.clear();//reseting the buffer cin.ignore(numeric_limits<streamsize>::max(),'\n');//empty the buffer cout<<"You have entered wrong input"<<endl; cout << "Enter first number: "; cin >> num1; } if(!cin.fail()) break; } cout << "Enter second number: "; cin >> num2; while(1){ if(cin.fail()){ cin.clear(); cin.ignore(numeric_limits<streamsize>::max(),'\n'); cout<<"You have entered wrong input"<<endl; cout <<...

  • Write the missing statements for the following program. #include <iostream> using namespace std; int main(void) {...

    Write the missing statements for the following program. #include <iostream> using namespace std; int main(void) { int Num1; cout << "Enter 2 numbers: ";    cin >> Num2; if (Num1 < Num2) cout << "Smallest number is " << Num1; else cout << "Smallest number is " << Num2;    return 0; }

  • Fix this code so only the function prototype comes before main. #include <iostream> using namespace std;...

    Fix this code so only the function prototype comes before main. #include <iostream> using namespace std; bool isMultiple(int num1, int num2) { return num1 % num2 == 0; } int main() { char ch = 'Y'; int num1, num2; while(ch =='Y') // While ch is equal to Y { cout << "Enter two numbers(largest first): "; cin >> num1; // Getting 1st number cin >> num2; // Getting 2nd number if(isMultiple(num1, num2)) cout << num2 << " " << "IS...

  • Game of Craps C++ #include <iostream> using namespace std; void roll (int *); // using pointer...

    Game of Craps C++ #include <iostream> using namespace std; void roll (int *); // using pointer to catch the random variable value of two dicerolls at one time . //these global variable with static variable win use to operate the working of code . //static win, account because two times input given by user to add the diceroll with win number and //account (means balance of user) . static int account = 100; static int win = 0; int bet...

  • #include <iostream> #include <cstdlib> #include <time.h> #include <string> using namespace std; int main() { srand(time (0));...

    #include <iostream> #include <cstdlib> #include <time.h> #include <string> using namespace std; int main() { srand(time (0)); int number, guess, response, reply; int score = 0 number = rand() % 100 + 1; do { do { cout << "Enter your guess "; cin >> guess; score++; if (guess < number) cout << guess << " is too low! Enter a higher number. "; else if (guess > number) cout << guess << " is too high! Enter a lower number....

  • This is C++ code for parking fee management program #include <iostream> #include <iomanip> using namespace std;...

    This is C++ code for parking fee management program #include <iostream> #include <iomanip> using namespace std; void input(char& car, int& ihour,int& imin, int& ohour, int& omin); void time(char car, int ihour, int imin, int ohour, int omin, int& phour, int& pmin, int& round, double& total); void parkingCharge (char car, int round, double& total); void print(char car, int ihour, int imin, int ohour, int omin, int phour, int pmin, int round, double total); int main() { char car; int ihour; int...

  • Find and fix errors #include <iostream> #include <cstdlib> #include <ctime> using namespace std; const int MIN...

    Find and fix errors #include <iostream> #include <cstdlib> #include <ctime> using namespace std; const int MIN = 1; const int MAX = 10; int getRandom(int low, int high); int main() {    int random_num = 0; int player_num; int tries; int seed = static_cast<int>(time(0)); bool guessed = false;    srand(seed); // call the getRandom function below       tries = 4; while ( tries > 0 && !guessed ) { cout << "Enter a number within the range 1 to...

  • Could someone re-write this code so that it first prompts the user to choose an option...

    Could someone re-write this code so that it first prompts the user to choose an option from the calculator (and catches if they enter a string), then prompts user to enter the values, and then shows the answer. Also, could the method for the division be rewritten to catch if the denominator is zero. I have the bulk of the code. I am just having trouble rearranging things. ------ import java.util.*; abstract class CalculatorNumVals { int num1,num2; CalculatorNumVals(int value1,int value2)...

  • #include <iostream> #include <sstream> #include <string> using namespace std; int main() {    const int index...

    #include <iostream> #include <sstream> #include <string> using namespace std; int main() {    const int index = 5;    int head = 0;    string s[index];    int flag = 1;    int choice;    while (flag)    {        cout << "\n1. Add an Item in the Chores List.";        cout << "\n2. How many Chores are in the list.";        cout << "\n3. Show the list of Chores.";        cout << "\n4. Delete an...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT